-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path187.cpp
More file actions
60 lines (54 loc) · 1.47 KB
/
Copy path187.cpp
File metadata and controls
60 lines (54 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
unordered_map<int, int> m;
vector<string> r;
for (int t = 0, i = 0; i < s.size(); i++)
if (m[t = (t<<3) | (s[i]&7) & 0x3FFFFFFF]++ == 1)
r.push_back(s.substr(i - 9, 10));
return r;
}
// vector<string> findRepeatedDnaSequences(string s) {
// vector<string> res;
// if(s.empty() || s.length() < 11)
// return res;
//
// map<char, int> ff;
// ff.insert(make_pair('A', 0));
// ff.insert(make_pair('T', 1));
// ff.insert(make_pair('C', 2));
// ff.insert(make_pair('G', 3));
//
// map<int, int> m_map;
// map<int, int>::iterator it;
//
// for(int i=0; i<s.length()-9; i++) {
//
// int sum = 0;
// for(int j=i; j<i+10; j++) {
// sum |= (ff[s[j]] << ((j-i)*2));
// }
//
// it = m_map.find(sum);
// if(it != m_map.end()) {
// if(it->second == 1){
// res.push_back(s.substr(i, 10));
// }
// it->second++;
// } else {
// m_map.insert(make_pair(sum, 1));
// }
// }
// return res;
// }
};
int main() {
Solution s;
s.findRepeatedDnaSequences("AAAAAGGGGGAAAAAGGGGGGAAAAACCCCTTT");
return 0;
}