Skip to content

Commit 8344680

Browse files
authored
Create 2044-count-number-of-maximum-bitwise-or-subsets.js
1 parent 4b10648 commit 8344680

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const countMaxOrSubsets = function(nums) {
6+
let res = 0, max = 0, n = nums.length
7+
for(let num of nums) max |= num
8+
dfs(0, 0)
9+
dfs(0, nums[0])
10+
return res
11+
12+
function dfs(i, cur) {
13+
if(i === n) return
14+
if(cur === max) return res += Math.pow(2, n - 1 - i)
15+
dfs(i + 1, cur)
16+
dfs(i + 1, cur | nums[i + 1])
17+
}
18+
};

0 commit comments

Comments
 (0)