class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
hashmap = {}
left = maxLen = 0
for i, c in enumerate(s):
if c in hashmap:
left = max(left, hashmap[c] + 1)
hashmap[c] = i
maxLen = max(maxLen, i - left + 1)
return maxLen
leetcode-003
最新推荐文章于 2022-07-03 19:16:41 发布