def find_max_substr(astring):
max_sub_str, temp = [], []
left_ptr, right_ptr = 0, 0
total = len(astring)
while right_ptr < total:
cur_str = astring[right_ptr]
if cur_str not in temp:
temp.append(cur_str)
right_ptr += 1
else:
if len(temp) > len(max_sub_str):
max_sub_str = temp
index = temp.index(cur_str)
left_ptr = left_ptr+index+1
temp = [astring[j] for j in range(left_ptr, right_ptr)]
if len(temp) > len(max_sub_str):
max_sub_str = temp
return max_sub_str
astring = 'asdfabcefghijk'
ret = find_max_substr(astring)
print(''.join(ret), len(ret))
'''
求最短子字符串
'''
def min_str(a_str):
min_str_temp,temp=a_str,[]
left,right=0,0
total=len(a_str)
while right<total:
cur_str=a_str[right]
if cur_str not in temp:
temp.append(cur_str)
right+=1
else:
if len(temp) < len(min_str_temp):
min_str_temp=temp
left = left+temp.index(cur_str)+1
temp=[a_str[j] for j in range(left,right)]
if len(temp) < len(min_str_temp):
min_str_temp = temp
return "".join(min_str_temp)
if __name__=="__main__":
a_str="abcde"
result=min_str(a_str)
print(result,a_str.count(result))