Merge pull request #472 from jackeyjia/patch-5
add js solution for combinationSum4
This commit is contained in:
commit
6e23fc4610
|
|
@ -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];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue