-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray5332.java
More file actions
37 lines (35 loc) · 917 Bytes
/
Array5332.java
File metadata and controls
37 lines (35 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* @ProjectName: leetcode
* @Package: array
* @ClassName: Array5332
* @Author: markey
* @Description:
* @Date: 2020/2/9 10:36
* @Version: 1.0
*/
public class Array5332 {
public static void main(String[] args) {
System.out.println(checkIfExist(new int[] {7,1,14,11}));
}
public static boolean checkIfExist(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
Set<Integer> set = new HashSet<>();
for (int i = 0; i < arr.length; i++) {
if (set.contains(arr[i] * 2)) {
return true;
}
if (set.contains(arr[i] / 2) && arr[i] % 2 == 0) {
return true;
}
set.add(arr[i]);
}
return false;
}
}