3. 无重复字符的最长子串
3. 无重复字符的最长子串
方法一
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ str_dic = {} i, ans = 0, 0 for j in range(len(s)): if s[j] in str_dic: i = max(str_dic[s[j]], i) ans = max(ans, j-i+1) str_dic[s[j]] = j + 1 return ans