From 248082f741629d49123e3b23b5ea476484b37a3a Mon Sep 17 00:00:00 2001 From: LehiChiang Date: Thu, 13 May 2021 20:19:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00377.=E7=BB=84=E5=90=88?= =?UTF-8?q?=E6=80=BB=E5=92=8C=E2=85=A3=20Python=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0377.组合总和Ⅳ.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md index b0b83718..fbede43d 100644 --- a/problems/0377.组合总和Ⅳ.md +++ b/problems/0377.组合总和Ⅳ.md @@ -148,9 +148,22 @@ C++测试用例有超过两个树相加超过int的数据,所以需要在if里 Java: - Python: +```python +class Solution: + def combinationSum4(self, nums, target): + dp = [0] * (target + 1) + dp[0] = 1 + + for i in range(1, target+1): + for j in nums: + if i >= j: + dp[i] += dp[i - j] + + return dp[-1] +``` + Go: @@ -161,4 +174,4 @@ Go: * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * B站视频:[代码随想录](https://space.bilibili.com/525438321) * 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) -
+
\ No newline at end of file