class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
length = len(s)
i = 0
temp = 0
while i < length:
slist = []
for each in range(i,length):
if s[each] not in slist:
slist.append(s[each])
if each == length - 1:
if len(slist) > temp:
temp = len(slist)
i += 1
break
else:
if len(slist) > temp:
temp = len(slist)
i += 1
break
return temp
还是暴力解法,感觉怎么写都是暴力写代码,还是书看少了,学习的少。这个题好像是可以用KMP算法,这个算法看了但不算看的很明白所以写不出来。立个Flag,这周末要写出KMP解法!