Fork me on GitHub

Repeated DNA Sequences

Description

https://leetcode.com/problems/repeated-dna-sequences/description/

Naive Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define LENGTH 10
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
vector<string> ret;
unordered_map<string, int> dict;
if (s.length() <= LENGTH) return ret;
for (int i = 0; i + 10 <= s.size(); i++) {
string target(s.substr(i, LENGTH));
if (dict[target] == 1) ret.push_back(target);
dict[target] += 1;
}
return ret;
}

};

[[1,0,0,1]

,[0,1,1,0],

[0,1,1,1],

[1,0,1,1]]

[0, 1, 1, 0]