Create 377-Combination-Sum-IV.java

This commit is contained in:
Kirigaya Kazuto 2016-10-27 21:10:42 +08:00 committed by GitHub
parent 6347db938c
commit 0a769ed9be

View File

@ -0,0 +1,14 @@
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];
}