3. Longest Substring Without Repeating Characters
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/
自我感觉难度/真实难度: 写题时间时长:
题意:
分析:
自己的代码:
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ start=maxlen=0 sueedChar={} for i in range(len(s)): if s[i] in sueedChar and start<=sueedChar[s[i]]: start=sueedChar[s[i]]+1 else: maxlen=max(maxlen,i-start+1) sueedChar[s[i]]=i return maxlen
start<=sueedChar[s[i]],主要是针对出现两个字母重复但是临近的时候。
代码效率/结果:
Runtime: 48 ms, faster than 89.58% of Python online submissions forLongest Substring Without Repeating Characters.
Memory Usage: 12.7 MB, less than 6.10% of Python online submissions forLongest Substring Without Repeating Characters.
优秀代码:
代码效率/结果:
自己优化后的代码:
反思改进策略: