C++ Solution, runtime error?


  • 0
    K

    What caused runtime error in the code when the input string is empty?

    public:
        vector<string> findRepeatedDnaSequences(string s) {
            //if(s.size()<=10) return {};
            unordered_map<string,int> mp;
            vector<string> res;
            for(int i=0;i<=s.size()-10;++i)
                if(mp[s.substr(i,10)]++==1)
                    res.push_back(s.substr(i,10));
            return res;
        }
    };

Log in to reply
 

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