DP java solution


  • 0
    N
     public int combinationSum4(int[] nums, int target) {
            if (target == 0 || nums.length == 0) {
                return 0;
            }
            Arrays.sort(nums);
            int[] M = new int[target + 1];
            M[0] = 1;
            for(int n = 1; n <= target; n++) {
                for(int num : nums) {
                    if(n < num) {
                        break;
                    }
                    M[n] += M[n - num];
                }
            }
            return M[target];
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.