Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
404 B
0
Indexable
Never
class Solution {
public:
    vector<string> findRepeatedDnaSequences(string s) {
        vector<string>repeated;
        unordered_map<string,int>mp;
        for(int i=0;i+9<s.length();i++){
            string dna=s.substr(i,10);
            mp[dna]++;
            if(mp[dna]==2) repeated.push_back(dna); //whats more than 1 will always pass thru 2
        }
        return repeated;
    }
};
Leave a Comment