mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Merge pull request #472 from jackeyjia/patch-5
add js solution for combinationSum4
This commit is contained in:
@ -201,6 +201,25 @@ func combinationSum4(nums []int, target int) int {
|
||||
}
|
||||
```
|
||||
|
||||
Javascript:
|
||||
```javascript
|
||||
const combinationSum4 = (nums, target) => {
|
||||
|
||||
let dp = Array(target + 1).fill(0);
|
||||
dp[0] = 1;
|
||||
|
||||
for(let i = 0; i <= target; i++) {
|
||||
for(let j = 0; j < nums.length; j++) {
|
||||
if (i >= nums[j]) {
|
||||
dp[i] += dp[i - nums[j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dp[target];
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
|
Reference in New Issue
Block a user