mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0377.组合总和Ⅳ.md
This commit is contained in:
@ -147,7 +147,23 @@ C++测试用例有超过两个树相加超过int的数据,所以需要在if里
|
|||||||
|
|
||||||
|
|
||||||
Java:
|
Java:
|
||||||
|
```Java
|
||||||
|
class Solution {
|
||||||
|
public int combinationSum4(int[] nums, int target) {
|
||||||
|
int[] dp = new int[target + 1];
|
||||||
|
dp[0] = 1;
|
||||||
|
for (int i = 0; i <= target; i++) {
|
||||||
|
for (int j = 0; j < nums.length; j++) {
|
||||||
|
if (i >= nums[j]) {
|
||||||
|
dp[i] += dp[i - nums[j]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[target];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user