You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
"""
class Solution:
# @return an integer
def lengthOfLongestSubstring(self, s):
start = 0
max_len = 0
d = {}
for i, char in enumerate(s):
if char in d:
start = max(start,d[char] + 1)
d[char] = i
max_len = max(max_len, i-start+1)
return max_len
# I did this totally by myself. Previous solution was wrong.