Leetcode 187. Repeated DNA Seque
2018-09-07 本文已影响3人
SnailTyan
文章作者: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;
}
};