Bitwise ORs of Subarrays LeetCode solution in Java

1
class Solution {
2
public int subarrayBitwiseORs(int[] arr) {
3
int n = arr.length;
4
Set<Integer> s = new HashSet();
5
LinkedList<Integer> queue = new LinkedList();
6
for (int i = 0; i < n; i++) {
7
int size = queue.size();
8
if (!queue.contains(arr[i])) {
9
queue.offer(arr[i]);
10
s.add(arr[i]);
11
}
12
int j = 0;
13
while (j < size) {
14
int tmp = queue.poll() | arr[i];
15
if (!queue.contains(tmp)) {
16
queue.offer(tmp);
17
s.add(tmp);
18
}
19
j++;
20
}
21
}
22
return s.size();
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0