java: add «1346. Check If N and Its Double Exist»

URL:	https://leetcode.com/problems/check-if-n-and-its-double-exist/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-12-01 18:16:39 +01:00
parent 03db4fc1c3
commit b2a1f19ea6
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,16 @@
import java.util.HashSet;
class Solution {
public boolean checkIfExist(int[] arr) {
var seen = new HashSet<Integer>();
for (var x : arr) {
if (seen.contains(2 * x) || ((x & 1) == 0 && seen.contains(x / 2))) {
return true;
}
seen.add(x);
}
return false;
}
}