Skip to content

Commit

Permalink
Time: 73 ms (27.71%), Space: 46.8 MB (14.62%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Oct 18, 2024
1 parent 0dd1a4a commit 9725cd9
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
List<Integer> or = new ArrayList<>();
public int countMaxOrSubsets(int[] nums) {
helper(0, nums, 0);
Collections.sort(or, Collections.reverseOrder());
int max = or.get(0);
int ans = 0;
for (Integer i: or){
if (max == i) ans++;
else break;
}
return ans;
}
public void helper(int index,int[] nums,int sum){
if (index == nums.length){
or.add(sum);
return;
}
int val = (sum | nums[index]);
helper(index+1,nums,val);
helper(index+1,nums,sum);
}
}

0 comments on commit 9725cd9

Please sign in to comment.