给定一个数组,m个数和为n的组合

public static List> calSum(int[] arr,int n,int m){
        if(arr==null){
            return null;
        }
        List> ans = new ArrayList<>();
        int len = arr.length;
        int bit = 1 << len;
        for(int i = 0;i list = new ArrayList<>();
               for(int j=0;j

统计一个数中二进制的个数

public static int numOf1(int n){
        int count = 0;
        while(n!=0){
            ++count;
            n = n & (n-1);
        }
        return count;
    }

你可能感兴趣的:(给定一个数组,m个数和为n的组合)