-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.py
More file actions
31 lines (27 loc) · 692 Bytes
/
3.py
File metadata and controls
31 lines (27 loc) · 692 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
27
28
29
30
31
import sys
class Solution:
def lengthOfLongestSubstring(self, s):
left = right = 0
n = len(s)
st = set()
l = 0
ans = 0
while right<n:
if s[right] not in st:
st.add(s[right])
right += 1
l += 1
ans = max(ans,l)
else:
while s[right] in st:
st.remove(s[left])
left += 1
l -= 1
return ans
def main():
line = sys.stdin.read().strip()
sol = Solution()
result = sol.lengthOfLongestSubstring(line)
print(result)
if __name__ == "__main__":
main()