congr / world

2 stars 1 forks source link

LeetCode : 377. Combination Sum IV #509

Closed congr closed 5 years ago

congr commented 5 years ago

https://leetcode.com/problems/combination-sum-iv/ image

congr commented 5 years ago
class Solution {
    public int combinationSum4(int[] nums, int target) {
        int[] D = new int[target+1];
        D[0] = 1;

        for (int s = 0; s <= target; s++) {
            for (int i = 0; i < nums.length; i++) {
                if (s - nums[i] >= 0)
                    D[s] += D[s - nums[i]];
            }
        }

        return D[target];
    }
}