当前位置:网站首页>leetcode刷题记录

leetcode刷题记录

2022-07-23 14:13:00 Five6667

上链接icon-default.png?t=M666https://leetcode.cn/problems/longest-substring-without-repeating-characters/

滑动窗口模板。 

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

 

原网站

版权声明
本文为[Five6667]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_43335470/article/details/125744383