My simple c++ solution


  • -1
    K
    class Solution {
    public:
    vector<string> findRepeatedDnaSequences(string s) {
        if(s.length() < 10)return {};
        vector<string>res;
        unordered_map<string, int>map;
        for(int i=0; i< s.length()-9; i++){
            string substr=s.substr(i, 10);
            if(map.find(substr)==map.end())map[substr]=1;
            else if(map[substr] ==1 ){
                res.push_back(substr);
                map[substr]++;
            }
        }
        return res;
        
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.