Skip to content

Commit c848414

Browse files
Merge pull request #2959 from zkws/master
修复0494.目标和题目Python二维DP解法中的错误
2 parents 7aa973b + 0afc3f7 commit c848414

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

problems/0494.目标和.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ class Solution:
684684
for i in range(1, len(nums)):
685685
for j in range(target_sum + 1):
686686
dp[i][j] = dp[i - 1][j] # 不选取当前元素
687-
if j >= nums[i - 1]:
687+
if j >= nums[i]: #只有j >= 本次遍历元素才可以选取当前元素
688688
dp[i][j] += dp[i - 1][j - nums[i]] # 选取当前元素
689689

690690
return dp[len(nums)-1][target_sum] # 返回达到目标和的方案数

0 commit comments

Comments
 (0)