文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
Repeated DNA Sequences2. Solution
class Solution {
public:
vector<string> findRepeatedDnaSequences(string s) {
vector<string> result;
map<string, int> mapping;
int length = s.length();
for(int i = 0; i < length - 9; i++) {
string substr = s.substr(i, 10);
mapping[substr]++;
if(mapping[substr] == 2) {
result.push_back(substr);
}
}
return result;
}
};
网友评论