Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<string> findRepeatedDnaSequences(string s) {
- vector<string> res;
- unordered_map<string, int> m;
- int n = s.size();
- for(int i = 0; i < n; i++) {
- string tmp = "";
- for(int j = i; j < min(i + 10, n); j++) {
- tmp += s[j];
- }
- if(tmp.size() == 10) {
- m[tmp]++;
- }
- }
- for(unordered_map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
- if(it->second > 1) {
- res.push_back(it->first);
- }
- }
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement