From cb7bf67a4e3a277ecf53ce37d0556c8e2e65f9f3 Mon Sep 17 00:00:00 2001 From: Steve2020 <841532108@qq.com> Date: Fri, 6 May 2022 11:08:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=880377.=E7=BB=84?= =?UTF-8?q?=E5=90=88=E6=80=BB=E5=92=8C=E2=85=A3.md=EF=BC=89=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0typescript=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0377.组合总和Ⅳ.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md index aaf27e61..1d808a3a 100644 --- a/problems/0377.组合总和Ⅳ.md +++ b/problems/0377.组合总和Ⅳ.md @@ -221,7 +221,27 @@ const combinationSum4 = (nums, target) => { }; ``` +TypeScript: + +```typescript +function combinationSum4(nums: number[], target: number): number { + const dp: number[] = new Array(target + 1).fill(0); + dp[0] = 1; + // 遍历背包 + for (let i = 1; i <= target; i++) { + // 遍历物品 + for (let j = 0, length = nums.length; j < length; j++) { + if (i >= nums[j]) { + dp[i] += dp[i - nums[j]]; + } + } + } + return dp[target]; +}; +``` + Rust + ```Rust impl Solution { pub fn combination_sum4(nums: Vec, target: i32) -> i32 {