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