Merge pull request #2959 from zkws/master

修复0494.目标和题目Python二维DP解法中的错误
This commit is contained in:
程序员Carl 2025-08-13 13:55:49 +08:00 committed by GitHub
commit c8484149bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 1 deletions

View File

@ -684,7 +684,7 @@ class Solution:
for i in range(1, len(nums)):
for j in range(target_sum + 1):
dp[i][j] = dp[i - 1][j] # 不选取当前元素
if j >= nums[i - 1]:
if j >= nums[i]: #只有j >= 本次遍历元素才可以选取当前元素
dp[i][j] += dp[i - 1][j - nums[i]] # 选取当前元素
return dp[len(nums)-1][target_sum] # 返回达到目标和的方案数