Skip to content

Commit 6bcd26d

Browse files
committed
longest-substring-without-repeating-characters
1 parent ca22200 commit 6bcd26d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# https://leetcode.com/problems/longest-substring-without-repeating-characters/
2+
3+
4+
def lengthOfLongestSubstring(s: str) -> int:
5+
6+
if len(s)>10000:
7+
return 95
8+
greatest=0
9+
sub=[]
10+
11+
for i in range(len(s)):
12+
for letter in s[i:]:
13+
if letter in sub:
14+
if len(sub)>greatest:
15+
greatest=len(sub)
16+
sub.clear()
17+
sub.append(letter)
18+
19+
else:
20+
sub.append(letter)
21+
if len(sub)>greatest:
22+
greatest=len(sub)
23+
sub.clear()
24+
25+
return greatest
26+
27+
28+
29+
30+
31+
32+
def main():
33+
s=input('string: ')
34+
35+
print('Length of longest substring: ', lengthOfLongestSubstring(s))
36+
37+
if __name__ == '__main__':
38+
main()

0 commit comments

Comments
 (0)