leetcode刷题记录

上链接icon-default.png?t=M666https://leetcode.cn/problems/longest-substring-without-repeating-characters/leetcode刷题记录_第1张图片

滑动窗口模板。 

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        cur, res = [], 0
        for r in range(len(s)):
            while s[r] in cur: 
                cur.pop(0) # 左边出
            cur.append(s[r]) # 右侧无论如何都会进入新的
            res = max(len(cur),res)
        return res

 

你可能感兴趣的:(leetcode,python,算法)