题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ab8d45e6c7a85d1c3390faa5e9c0548f.png)
官方解答
class Solution:
def checkIfExist(self, arr: List[int]) -> bool:
arr.sort()
q = 0
for p in range(len(arr)):
while q < len(arr) and arr[p] * 2 > arr[q]:
q += 1
if q != len(arr) and p != q and arr[p] * 2 == arr[q]:
return True
q = len(arr) - 1
for p in range(len(arr) - 1, -1, -1):
while q > -1 and arr[p] * 2 < arr[q]:
q -= 1
if q != -1 and p != q and arr[p] * 2 == arr[q]:
return True
return False
作者:LeetCode-Solution
链接:https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/solution/jian-cha-zheng-shu-ji-qi-liang-bei-shu-shi-fou-cun/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。