题目链接:https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/
难度:中等
描述:
请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。
题解
class Solution:def lengthOfLongestSubstring(self, s: str) -> int:char_set = set()left = 0ret = 0for right in range(len(s)):if s[right] in char_set:while s[right] in char_set:char_set.remove(s[left])left += 1char_set.add(s[right])ret = max(ret, right - left + 1)return ret
