Skip to content

Commit 1964a00

Browse files
authored
Create Longest-Substring-Without-Repeating-Characters.py
1 parent 46d54df commit 1964a00

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def lengthOfLongestSubstring(self, s: str) -> int:
3+
if len(s) == 0:
4+
return 0
5+
6+
longest_substring = 1
7+
substring_set = set()
8+
9+
index = 0
10+
while index < len(s):
11+
if s[index] not in substring_set:
12+
seeker = index + 1
13+
substring_set.add(s[index])
14+
while seeker < len(s) and s[seeker] not in substring_set:
15+
substring_set.add(s[seeker])
16+
seeker += 1
17+
longest_substring = max(longest_substring, seeker - index)
18+
substring_set.clear()
19+
index += 1
20+
else:
21+
index += 1
22+
return longest_substring

0 commit comments

Comments
 (0)