Matej Focko
b2a1f19ea6
URL: https://leetcode.com/problems/check-if-n-and-its-double-exist/ Signed-off-by: Matej Focko <me@mfocko.xyz>
16 lines
306 B
Java
16 lines
306 B
Java
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;
|
|
}
|
|
}
|