Merge pull request #295 from dark-Qy/master

修改494 dp解法,添加条件判断
This commit is contained in:
halfrost
2024-12-10 15:14:40 -08:00
committed by GitHub

View File

@ -6,7 +6,7 @@ func findTargetSumWays(nums []int, S int) int {
for _, n := range nums { for _, n := range nums {
total += n total += n
} }
if S > total || (S+total)%2 == 1 || S+total < 0 { if S+total < 0 || S > total || (S+total)%2 == 1 {
return 0 return 0
} }
target := (S + total) / 2 target := (S + total) / 2