Concise C++ code using char table


  • 0
    int lengthOfLongestSubstring(string s) {
        int i = 0, j = 0, len = 0, tbl[128] = {0};
        while( j < s.size() ) {
            tbl[s[j]]++;
            while( tbl[s[j]] > 1 ) tbl[s[i++]]--;
            len = max( len, j - i + 1 );
            j++;
        }
        return len;
    }

Log in to reply
 

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