Count Number of Maximum Bitwise-OR Subsets

给一个数组, 求里面最大or运算结果的子集的多少。

暴力

class Solution {
    int res = 0;
    public int countMaxOrSubsets(int[] nums) {
        int max = 0;
        for(int n : nums)
            max |= n; 
        dfs(nums, max, 0, 0);
        return res;
    }
    public void dfs(int[] nums,int max,int tmp, int pos){
        if(tmp == max)
            res++;
        if(pos >= nums.length)
            return;
        for(int i = pos; i < nums.length; i++){
            int tt = tmp;
            dfs(nums, max, tmp | nums[i], i+1);
            tmp = tt;
         }
    }
}