题解 | #重复的DNA序列#
重复的DNA序列
http://www.nowcoder.com/practice/fe9099e5308042a8af2f7aabdb3719fe
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param DNA string字符串 1
* @return string字符串vector
*/
vector<string> repeatedDNA(string DNA) {
// write code here
int len = 10;
vector<string> ans;
unordered_map<string, int> map;
for(int i = 0; i <= DNA.size() - 10; i++) {
string s = DNA.substr(i, 10);
map[s]++;
if(map[s] == 2)
ans.push_back(s);
}
return ans;
}
};