Short, Clean and Fast Solution


  • 0
    G
    class Solution {
        public int lengthOfLongestSubstring(String s) {
            int [] map = new int [256];
            char [] A = s.toCharArray();
            int max = 0;
            int j = 0;
            int count = 0;
            for (int i = 0; i < s.length(); i++) {
                while (map[A[i]] > 0) {
                    map[A[j]]--;
                    j++;
                }
                max = Math.max(max, i - j + 1);
                map[A[i]]++;
            }
            return max; 
        }
    }
    

Log in to reply
 

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