Skip to content

Instantly share code, notes, and snippets.

@jesuscmadrigal
Created April 11, 2024 23:10
Show Gist options
  • Save jesuscmadrigal/adec6c63b2855527394540a48adc3cc9 to your computer and use it in GitHub Desktop.
Save jesuscmadrigal/adec6c63b2855527394540a48adc3cc9 to your computer and use it in GitHub Desktop.
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
left, maxSub, seen = 0, 0, set()
for right in range(len(s)):
while s[right] in seen:
seen.remove(s[left])
left += 1
seen.add(s[right])
maxSub = max(maxSub, (right - left) + 1)
return maxSub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment