mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
@ -272,7 +272,8 @@ Python:
|
|||||||
class Solution:
|
class Solution:
|
||||||
def findTargetSumWays(self, nums: List[int], target: int) -> int:
|
def findTargetSumWays(self, nums: List[int], target: int) -> int:
|
||||||
sumValue = sum(nums)
|
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
|
bagSize = (sumValue + target) // 2
|
||||||
dp = [0] * (bagSize + 1)
|
dp = [0] * (bagSize + 1)
|
||||||
dp[0] = 1
|
dp[0] = 1
|
||||||
|
Reference in New Issue
Block a user