My concise solution in C++


  • 5
    Y

    Share my accepted solution.

    vector<string> findRepeatedDnaSequences(string s) {
    
        int size=s.size();
        hash<string> mapping;
        unordered_set<int> hasOccurred;
        vector<string> result;
        vector<string>::iterator iter;
        
        for(int i=0;i<=size-10;i++){
            string temp=s.substr(i,10);
            if(hasOccurred.find(mapping(temp))!=hasOccurred.end()){
                iter=find(result.begin(),result.end(),temp);
                if(iter==result.end())
                    result.push_back(temp);
            }
            else
                hasOccurred.insert(mapping(temp));
        }
        return result;
    }

Log in to reply
 

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