Skip to content
LC-1346 Easy LeetCode

1346. Check If N and Its Double Exist

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 41% Topics: Array, Hash Table, Two Pointers, Binary Search, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

class Solution(object):
    def checkIfExist(self, arr):
        """
        :type arr: List[int]
        :rtype: bool
        """
        lookup = set()
        for x in arr:
            if 2*x in lookup or \
               (x%2 == 0 and x//2 in lookup):
                return True
            lookup.add(x)
        return False

Solution from kamyu104/LeetCode-Solutions · MIT