Py3 - Solution: 123456789101112 class : def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ list_s = list(s) for i in range(len(set(list_s)),-1,-1): for j in range(0,len(s)-i+1): if len(set(list(s[j:j+i]))) == i: return i 123456789101112131415161718 class : def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ finded = {} start = 0 max_length = 0 for i in range(len(s)): if s[i] in finded and finded[s[i]] >= start: start = finded[s[i]]+1 else: if i - start + 1 > max_length: max_length = i - start + 1 finded[s[i]] = i return max_length 解决方案 赞微海报分享
近期评论