#3
Longest Substring Without Repeating Characters
medium· Sliding Windowruns: 0Given a string s, find the length of the longest substring without duplicate characters.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 371
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
seen = set()
left = 0
longest = 0
for right in range(len(s)):
while s[right] in seen:
seen.remove(s[left])
left += 1
seen.add(s[right])
longest = max(longest, right - left + 1)
return longest
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.