Leetcode 187. Repeated DNA Sequences

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Repeated DNA Sequences

2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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;
}
};

Reference

  1. https://leetcode.com/problems/repeated-dna-sequences/description/
如果有收获,可以请我喝杯咖啡!