494题python代码修正

This commit is contained in:
Xiaofei-fei
2022-02-02 18:47:01 +08:00
parent d300529b68
commit 2f1c56e6dd
2 changed files with 2 additions and 1 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -272,7 +272,8 @@ Python
class Solution:
def findTargetSumWays(self, nums: List[int], target: int) -> int:
sumValue = sum(nums)
if target > sumValue or (sumValue + target) % 2 == 1: return 0
#注意边界条件为 target>sumValue or target<-sumValue or (sumValue + target) % 2 == 1
if abs(target) > sumValue or (sumValue + target) % 2 == 1: return 0
bagSize = (sumValue + target) // 2
dp = [0] * (bagSize + 1)
dp[0] = 1