blob: cee017422218985fd5d3483e39a3e9de4b2d4583 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# 1346. Check If N and Its Double Exist
"""
given an array 'arr' of integers, check if there exists two indices 'i' and
'j' such that 'i != j', '0 <= i, j < arr.length', and 'arr[i] == 2 * arr[j]'
"""
class Solution(object):
def checkIfExist(self, arr):
"""
:type arr: List[int]
:rtype: bool
"""
seen = set()
for i in arr:
if 2 * i in seen or i / 2 in seen:
return True
seen.add(i)
return False
if __name__ == "__main__":
obj = Solution()
print(obj.checkIfExist(arr=[10, 2, 5, 3]))
print(obj.checkIfExist(arr=[3, 1, 7, 11]))
|