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
原文地址:https://www.cnblogs.com/xiao-xue-di/p/10287135.html
时间: 2024-09-29 23:44:15