longest_substring_without_repeating_characters
longest_substring_without_repeating_characters.py 源码
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
res, m = 0, {}
for c in s:
if c in m:
res = max(res, len(m))
m.clear()
m[c] = 1
return max(res, len(m))
if __name__ == "__main__":
sol = Solution()
r = sol.lengthOfLongestSubstring("abcabcbb")
print(r)
你可能感兴趣的文章
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦