classSolution: defcheckIfExist(self, arr: List[int]) -> bool: # 暴力枚举方法 # for i in range(len(arr)): # for j_value in arr[i+1:]: # if arr[i]==2*j_value or 2*arr[i]==j_value: # return True # return False # 二分法 arr.sort() whilelen(arr)>1: if arr[len(arr)-1]>=0: # 正数 last = arr.pop() left = 0 right = len(arr)-1 while left<=right: mid = (left+right)>>1 if2*arr[mid]==last: returnTrue elif2*arr[mid]>last: right = mid-1 else: left = mid+1 if arr[len(arr)-1]<0: # 负数 first = arr.pop(0) left = 0 right = len(arr)-1 while left<=right: mid = (left+right)>>1 if2*arr[mid]==first: returnTrue elif2*arr[mid]>first: right = mid-1 else: left = mid+1 returnFalse