Count Number of Maximum Bitwise-OR Subsets LeetCode solution in JavaScript

1
/**
2
* @param {number[]} nums
3
* @return {number}
4
*/
5
var countMaxOrSubsets = function (nums) {
6
let n = nums.length;
7
let len = Math.pow(2, n);
8
let ans = 0;
9
let hash = {};
10

11
for (let i = 0; i < len; i++) {
12
let tmp = 0;
13
for (let j = 0; j < n; j++) {
14
if (i & (1 << j)) {
15
tmp |= nums[j];
16
}
17
}
18
if (hash[tmp]) {
19
hash[tmp] += 1;
20
} else {
21
hash[tmp] = 1;
22
}
23
ans = Math.max(ans, tmp);
24
}
25

26
return hash[ans];
27
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0