OJ-Problems-Source/LeetCode/377-Combination-Sum-IV.java

15 lines
319 B
Java
Raw Normal View History

2016-10-27 21:10:42 +08:00
public int combinationSum4(int[] nums, int target) {
int dp[] = new int[target + 1];
for (int i = 0; i <= target; i++) {
for (int k = 0; k < nums.length; k++) {
if (i - nums[k] > 0) {
dp[i] += dp[i - nums[k]];
} else if (i - nums[k] == 0) {
dp[i] += 1;
}
}
}
return dp[target];
}