LeetCode/java/check-if-n-and-its-double-exist.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;
}
}