diff --git a/java/check-if-n-and-its-double-exist.java b/java/check-if-n-and-its-double-exist.java new file mode 100644 index 0000000..0cd7d44 --- /dev/null +++ b/java/check-if-n-and-its-double-exist.java @@ -0,0 +1,16 @@ +import java.util.HashSet; + +class Solution { + public boolean checkIfExist(int[] arr) { + var seen = new HashSet(); + for (var x : arr) { + if (seen.contains(2 * x) || ((x & 1) == 0 && seen.contains(x / 2))) { + return true; + } + + seen.add(x); + } + + return false; + } +}