Why error here (can be run succ with Visual Studio)

  • 1
    unordered_map<string,bool> fWords;
    bool wordBreak(string s, unordered_set<string>& wordDict) {
        if(s.size()==0) return true;
        if(fWords.count(s)) return fWords[s];
        if(wordDict.count(s)){fWords[s]=true; return true;}
        for(int i=1;i<s.size();i++)
            string str1=s.substr(0,i);
            string str2=s.substr(i);
            if(!fWords.count(str1)) fWords[str1]=wordBreak(str1,wordDict);
            if(!fWords.count(str2)) fWords[str2]=wordBreak(str2,wordDict);
            if(fWords[str1]&&fWords[str2]) return true;
        return false;

    error when input is "ab", dict={"a","b"}, why?

Log in to reply

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