# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # 题解 https://leetcode.cn/problems/longest-substring-without-repeating-characters/submissions/ # # @param arr int整型一维数组 the array # @return int整型 # class Solution: def maxLength(self , arr: List[int]) -> int: # write code here n=len(arr) ans=0 rk=-1 # 设置一个向右的指针 st=set() for i in range(0,n): if i!=0: st.remove(arr[i-1]) while rk+1<n and arr[rk+1] not in st: st.add(arr[rk+1]) rk+=1 ans=max(ans,len(st)) return ans def maxLength1(self , arr: List[int]) -> int: # write code here n=len(arr) ans=0 if n==1: return 1 for i in range(n-1): st=set() st.add(arr[i]) for j in range(i+1,n): if arr[j] in st: break else: st.add(arr[j]) #print(st) ans=max(ans,len(st)) return ans