Skip to content

Commit fa05b46

Browse files
authored
Create check-if-n-and-its-double-exist.py
1 parent 80efe89 commit fa05b46

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def checkIfExist(self, arr):
6+
"""
7+
:type arr: List[int]
8+
:rtype: bool
9+
"""
10+
lookup = set()
11+
for x in arr:
12+
if 2*x in lookup or \
13+
(x%2 == 0 and x//2 in lookup):
14+
return True
15+
lookup.add(x)
16+
return False

0 commit comments

Comments
 (0)