Key:
- Fixed size window,
right
should start from9
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
int left = 0;
unordered_set<string> results;
unordered_set<string> hset;
for (auto right = 9; right < s.size(); right++) {
string sub(s, left, 10);
if (hset.find(sub) != hset.end()) {
results.insert(sub);
}
hset.insert(sub);
left++;
}
return vector<string>(results.begin(), results.end());
}
};