Project

General

Profile

Files » strlong.py

UserName LastName, 02/14/2025 10:40 AM

 
# 编写一个算法,实现从一个字符串中找出最长的不重复的字符串
def strlong(str1):
str0=[]
#取出以每个字母开头所有最长字符串
for x in str1:
for y in str1[str1.index(x):len(str1)-1]:
str_x=''
if y not in x:
str_x=x + y
else:
str0.append(str_x)

#比较长度
max=''
for s in str0:
if len(s)>len(max):
max=s

return max

(171-171/437)