From b2a1f19ea60718718857e670b1bc28bf7f0d7af3 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sun, 1 Dec 2024 18:16:39 +0100 Subject: [PATCH] =?UTF-8?q?java:=20add=20=C2=AB1346.=20Check=20If=20N=20an?= =?UTF-8?q?d=20Its=20Double=20Exist=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/check-if-n-and-its-double-exist/ Signed-off-by: Matej Focko --- java/check-if-n-and-its-double-exist.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 java/check-if-n-and-its-double-exist.java 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; + } +}