mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 377-Combination-Sum-IV.java
This commit is contained in:
parent
6347db938c
commit
0a769ed9be
14
LeetCode/377-Combination-Sum-IV.java
Normal file
14
LeetCode/377-Combination-Sum-IV.java
Normal 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];
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user