num=[1,3,6,7,9,10,14,15] s="abcabcbb" def two_part(num,target): left=0 right=len(num)-1 while(left<=right): mid=(left+right)//2 if num[mid]<target:left=mid+1 elif num[mid]>target:right=mid-1 else:return mid return False def two_sum(num,target): left=0 right=len(num)-1 while(left<right): if num[left]+num[right]>target:right-=1 elif num[left]+num[right]<target:left+=1 else:return [left,right] return False def max_long_str(s): left=right=0 max_len=0 max_s=[] while(right!=len(s)-1): right+=1 mid_list=[i for i in s[left:right+1]] while(len(mid_list)!=len(list(set(mid_list)))): left+=1 mid_list.pop(0) if max_len<right-left+1: max_len=right-left+1 max_s=[s[left:right+1]] elif max_len==right-left+1: max_s.append(s[left:right+1]) return max_s print(max_long_str(s))
本代码为视频https://www.bilibili.com/video/BV1PT4y1u782/
的原始代码,详情请观看视频内容