My simple c++ solution


  • 11
    K
    class Solution {
    public:
    int lengthOfLongestSubstring(string s) {
        vector<int> table(256, 0);
        int maxstr=0, track=0;
        for(int i=0;i<s.length();i++)
        {
            while(table[s[i]])table[s[track++]]=0;
            table[s[i]]=1;
            maxstr=max(maxstr, i-track+1);
            
        }
        return maxstr;
    }
    

    };


  • 1
    L

    Hey, can you explain why table (256,0). The code seems to work with table(0,0)


Log in to reply
 

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