-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path898.java
More file actions
41 lines (40 loc) · 1.3 KB
/
898.java
File metadata and controls
41 lines (40 loc) · 1.3 KB
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
38
39
40
41
__________________________________________________________________________________________________
sample 146 ms submission
class Solution {
public int subarrayBitwiseORs(int[] A) {
int[] cur = new int[33], next = new int[33];
int n1 = 0;
HashSet<Integer> set = new HashSet<>();
for (int a : A) {
int n2 = 0;
set.add(next[n2++] = a);
for (int i = 0; i < n1; i++) {
int a2 = a | cur[i];
if (a2 != a) {
set.add(next[n2++] = a = a2);
}
}
int[] temp = cur; cur = next; next = temp;
n1 = n2;
}
return set.size();
}
}
__________________________________________________________________________________________________
sample 69664 kb submission
class Solution {
public int subarrayBitwiseORs(int[] A) {
Set<Integer> res = new HashSet<>(), cur = new HashSet<>(), next;
for (int i : A) {
next = new HashSet<>();
next.add(i);
for (int j : cur) {
next.add(j | i);
}
cur = next;
res.addAll(cur);
}
return res.size();
}
}
__________________________________________________________________________________________________