Skip to content

Commit 3155ca1

Browse files
committed
Time: 53 ms (68.16%) | Memory: 16.6 MB (88.86%) - LeetSync
1 parent 07d495c commit 3155ca1

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
from collections import defaultdict
12
class Solution:
23
def lengthOfLongestSubstring(self, s: str) -> int:
3-
4-
hashMap = {}
5-
left = 0
4+
map = defaultdict(int)
65
ans = 0
6+
left = 0
77

8-
for r in range(len(s)):
9-
10-
if s[r] in hashMap:
11-
#do soemthing
12-
left = max(left, hashMap[s[r]]+1)
8+
for right, char in enumerate(s):
139

14-
hashMap[s[r]] = r
15-
ans = max(ans, r - left +1)
16-
17-
return ans
1810

11+
if char in map:
12+
#dop stuiff
13+
left = max(map[char] +1 , left)
14+
ans = max(ans, right - left +1)
15+
map[char] = right
16+
return ans
1917

18+
2019

0 commit comments

Comments
 (0)