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:
parent
03db4fc1c3
commit
b2a1f19ea6
1 changed files with 16 additions and 0 deletions
16
java/check-if-n-and-its-double-exist.java
Normal file
16
java/check-if-n-and-its-double-exist.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue