From 1e34731c0de0cc457e3a9d9bd28d9df18b06a7f4 Mon Sep 17 00:00:00 2001 From: Qi Jia <13632059+jackeyjia@users.noreply.github.com> Date: Tue, 6 Jul 2021 19:58:28 -0700 Subject: [PATCH] add js solution for combinationSum4 --- problems/0377.组合总和Ⅳ.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md index d0394706..2ee009b3 100644 --- a/problems/0377.组合总和Ⅳ.md +++ b/problems/0377.组合总和Ⅳ.md @@ -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]; +}; +``` + -----------------------