Short 8 lines C++ O(n) solution


  • 2
        vector<string> findRepeatedDnaSequences(string s) {
            vector<string>res;
            unordered_map<string, int>m;
            for(int i = 0; i + 10 <= s.size(); i++){
                string seq = s.substr(i, 10);
                if(m[seq] == 1) res.push_back(seq);
                m[seq]++;
            }
            return res;
        }
    

Log in to reply
 

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