Advertisement
Josif_tepe

Untitled

Dec 14th, 2023
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<string> findRepeatedDnaSequences(string s) {
  4.         vector<string> res;
  5.         unordered_map<string, int> m;
  6.         int n = s.size();
  7.         for(int i = 0; i < n; i++) {
  8.             string tmp = "";
  9.             for(int j = i; j < min(i + 10, n); j++) {
  10.                 tmp += s[j];
  11.             }
  12.             if(tmp.size() == 10) {
  13.                 m[tmp]++;
  14.             }
  15.         }
  16.         for(unordered_map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
  17.             if(it->second > 1) {
  18.                 res.push_back(it->first);
  19.             }
  20.         }
  21.         return res;
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement