Skip to content

Commit 2d888b4

Browse files
Create 003_Longest_Substring_Without_Repeating_Characters.py
1 parent ef08eb0 commit 2d888b4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution(object):
2+
def lengthOfLongestSubstring(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
mapSet = {}
8+
start, result = 0, 0
9+
10+
for end in range(len(s)):
11+
if s[end] in mapSet:
12+
start = max(mapSet[s[end]], start)
13+
result = max(result, end-start+1)
14+
mapSet[s[end]] = end+1
15+
16+
return result
17+

0 commit comments

Comments
 (0)