We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7aa973b commit 0afc3f7Copy full SHA for 0afc3f7
problems/0494.目标和.md
@@ -684,7 +684,7 @@ class Solution:
684
for i in range(1, len(nums)):
685
for j in range(target_sum + 1):
686
dp[i][j] = dp[i - 1][j] # 不选取当前元素
687
- if j >= nums[i - 1]:
+ if j >= nums[i]: #只有j >= 本次遍历元素才可以选取当前元素
688
dp[i][j] += dp[i - 1][j - nums[i]] # 选取当前元素
689
690
return dp[len(nums)-1][target_sum] # 返回达到目标和的方案数
0 commit comments