#查找一个字符串中最长不重复连续子字符串。
def find_str(content):
ret ='' "
for iin range(len(content)-1):
tmp = content[i]
if len(ret) >len(content[i:]):
break
for jin range(i+1,len(content)):
if content[j]not in tmp:
tmp += content[j]
else:
break
if len(tmp) >=len(ret):
ret = tmp
print(ret)
l ="pwkkeacbw"
find_str(l)
#方法二
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
li=""
ret=""
for i in s:
if i not in li:
li+=i
else:
li = li[li.index(i)+1:]
li+=i
if len(li) > len(ret):
ret = li
return len(ret)
find1(l)
网友评论