题目链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
if len(s) == 0:
return 0
else:
tmpList = []
resultList = []
position = 0
for i in range(len(s)):
if s[i] in tmpList:
resultList.append(len(tmpList))
position = tmpList.index(s[i])
tmpList = tmpList[(position+1):]
tmpList.append(s[i])
else:
tmpList.append(s[i])
if i == len(s) - 1:
resultList.append(len(tmpList))
resultList.sort()
return resultList[len(resultList)-1]
执行用时 :72 ms, 在所有 Python3 提交中击败了75.87%的用户
内存消耗 :13.8 MB, 在所有 Python3 提交中击败了5.88%的用户