Java 37ms, Beats 99.59%


  • 0
    K

    class Solution {

    public int lengthOfLongestSubstring(String s) {
        int max = 0, i = 0, j = 0;
        int[] table = new int[256];
        
        while (j < s.length()) {
            char ch = s.charAt(j);
            if (table[ch] > i) {
                max = Math.max(j - i, max);
                i = table[ch];
            }
            table[ch] = ++j;
        }
        return Math.max(max, j - i);
    }
    

    }


Log in to reply
 

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