给定一个字符串 s ,请你找出其中不含有重复字符的 最长连续子字符串 的长度。
示例 1:
输入: s = “abcabcbb”
输出: 3
解释: 因为无重复字符的最长子字符串是 “abc”,所以其长度为 3。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/wtcaE1
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
arr = []
result = 0
for i in s:
if i in arr:
result = max(result, len(arr))
while i in arr:
arr.pop(0)
arr.append(i)
return max(result, len(arr))