Skip to content

Commit 1e34731

Browse files
authored
add js solution for combinationSum4
1 parent 2e10346 commit 1e34731

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

problems/0377.组合总和Ⅳ.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ func combinationSum4(nums []int, target int) int {
201201
}
202202
```
203203

204+
Javascript:
205+
```javascript
206+
const combinationSum4 = (nums, target) => {
207+
208+
let dp = Array(target + 1).fill(0);
209+
dp[0] = 1;
210+
211+
for(let i = 0; i <= target; i++) {
212+
for(let j = 0; j < nums.length; j++) {
213+
if (i >= nums[j]) {
214+
dp[i] += dp[i - nums[j]];
215+
}
216+
}
217+
}
218+
219+
return dp[target];
220+
};
221+
```
222+
204223

205224

206225
-----------------------

0 commit comments

Comments
 (0)