Skip to content

Commit 5186e09

Browse files
committed
Time: 8 ms (86.00%), Space: 41 MB (69.30%) - LeetHub
1 parent 964117b commit 5186e09

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int countMaxOrSubsets(int[] nums) {
3+
int maxOr = 0;
4+
5+
for(int e : nums) maxOr |= e;
6+
7+
return dfs(nums, 0, 0, maxOr);
8+
}
9+
10+
private int dfs(int[] nums, int i, int currOr, int maxOr) {
11+
if(i == nums.length) return currOr == maxOr ? 1 : 0;
12+
13+
return dfs(nums, i + 1, currOr | nums[i], maxOr) + dfs(nums, i + 1, currOr, maxOr);
14+
}
15+
}

0 commit comments

Comments
 (0)