-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathq0003.py
More file actions
26 lines (25 loc) · 700 Bytes
/
q0003.py
File metadata and controls
26 lines (25 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
_set = set()
length = len(s)
count = 0
result = 0
start = 0
for i in range(length):
char = s[i]
if char not in _set:
_set.add(char)
count += 1
else:
while s[start] != char:
_set.remove(s[start])
start += 1
count -= 1
start += 1
print(start)
if count > result:
result = count
return result
str = "tmmzuxt"
result = Solution().lengthOfLongestSubstring(str)
print(result)