Skip to content

Commit 89c6f0b

Browse files
committed
solve longest substring without repeating characters
1 parent 3b17347 commit 89c6f0b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# TC : O(n)
2+
# SC : O(n)
3+
class Solution:
4+
def lengthOfLongestSubstring(self, s: str) -> int:
5+
charSet = set()
6+
left = 0
7+
longest_length = 0
8+
9+
for right in range(len(s)):
10+
while s[right] in charSet:
11+
charSet.remove(s[left])
12+
left += 1
13+
charSet.add(s[right])
14+
longest_length = max(longest_length, right - left + 1)
15+
16+
return longest_length

0 commit comments

Comments
 (0)