-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3.py
More file actions
29 lines (27 loc) · 747 Bytes
/
Q3.py
File metadata and controls
29 lines (27 loc) · 747 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
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
length = len(s)
p=0
max = 0
while(p<length and max < length - p):
q=p
tempLen = 0
strSet = set()
while(q<length):
if s[q:q+1] in strSet:
break
else:
strSet.add(s[q:q+1])
q+=1
tempLen+=1
if max<tempLen:
max = tempLen
p+=1
return max
if __name__ == '__main__':
solution = Solution()
print(solution.lengthOfLongestSubstring("adfgdfhgad"))