-
Notifications
You must be signed in to change notification settings - Fork 0
/
q3_longest_substring.py
43 lines (34 loc) · 1.12 KB
/
q3_longest_substring.py
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
32
33
34
35
36
37
38
39
40
41
42
43
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
str_list = []
max_length = 0
for x in s:
if x in str_list:
str_list = str_list[str_list.index(x)+1:]
str_list.append(x)
max_length = max(max_length, len(str_list))
return max_length
"""
maximum = 0
counter = 0
last = None
seen = []
for iterator, character in enumerate(s):
if character == last and character in seen:
counter = 1
last = character
seen = []
seen.append(character)
elif character in seen:
counter = 1
last = character
seen = []
seen.append(character)
else:
counter = counter + 1
last = character
seen.append(character)
if maximum < counter:
maximum = counter
return maximum
"""