Share my easy to understand code


  • 0
    O
    class Solution {
    public:
        vector<string> findRepeatedDnaSequences(string s) {
            unordered_map<string, int> DNA;
            vector<string> ans;
            for (int i = 10; i <= s.size(); i++) {
                DNA[s.substr(i - 10, 10)]++;
                if (DNA[s.substr(i - 10, 10)] == 2)
                    ans.push_back(s.substr(i - 10, 10));
            }
            return ans;
        }
    };

Log in to reply
 

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