C# - 2 pointer - 8 lines


  • 0
        public int LengthOfLongestSubstring(string s) 
        {
            int[] map = new int[256];
            int left = 0;
            int max = 0;
            for (int i = 0; i < s.Length; i++)
            {
                while (map[s[i]] != 0) map[s[left++]]--;
                map[s[i]]++;
                max = Math.Max(i - left + 1, max);
            }
            return max;
        }
    

Log in to reply
 

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