给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串的长度。
示例:
输入: s = “abcabcbb”
输出: 3
解释: 因为无重复字符的最长子串是 “abc”,所以其长度为 3。
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
result = 0
length = len(s)
res = set()
right = -1
for i in range(length):
if i > 0:
res.remove(s[i - 1])
while right + 1 < length and s[right + 1] not in res:
res.add(s[right + 1])
right += 1
result = max(result, right - i + 1)
return result



