0
点赞
收藏
分享

微信扫一扫

LeetCode题解(0377):组合总和IV(Python)


题目:​​原题链接​​(中等)

标签:动态规划、数组

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

O ( N 2 )

O ( N )

60ms (25.32%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def combinationSum4(self, nums: List[int], target: int) -> int:
dp = [0] * (target + 1)
dp[0] = 1
for i in range(1, target + 1):
for num in nums:
if num <= i:
dp[i] += dp[i - num]
return dp[target]


举报

相关推荐

0 条评论