LC003 - Longest Substring Without Repeating Characters
Problem
Example
Solution
def lengthOfLongestSubstring(self, s: str) -> int:
maxLen = 0
asciiIndex = [-1] * 128
left = 0
for right in range(len(s)):
if asciiIndex[ord(s[right])] >= left:
left = asciiIndex[ord(s[right])] + 1
asciiIndex[ord(s[right])] = right
maxLen = max(maxLen, right - left + 1)
return maxLenLast updated