i don't know.. please help..


  • 0
    S

    ...
    class Solution {
    public:
    int lengthOfLongestSubstring(string s)
    {
    int i = 0, j = 0, cnt = 0, len = s.length();
    set<char> str;
    set<char>::iterator sIt;

        while(i < len && j < len)
        {
            char ch = s.at(j);
            sIt = str.find(ch);
            
            if(sIt == str.end())
            {
                str.insert(ch);
                j++;
                cnt = max(cnt, j - i);
            }
            else
            {
                str.erase(sIt);
                i++;
            }
        }
        return cnt;
    }
    

    };

    case pwwkew..
    error.. why??


  • 0
    M

    the mistake is obvious,just run the program step by step on paper then you will find it


Log in to reply
 

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