Leetcode Problem 1346. Check If N and Its Double Exist

1346. Check If N and Its Double Exist

Leetcode Solutions

Using HashSet to Check for Double or Half

  1. Initialize an empty HashSet.
  2. Iterate through each element in the array.
  3. For each element, check if the HashSet contains either half of it or twice it.
    • If yes, return true.
    • If no, add the element to the HashSet.
  4. If the end of the array is reached without finding a pair, return false.
UML Thumbnail

Brute Force Pairwise Comparison

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...