0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int:
v = (sum(nums)+target)/2 if v - int(v) != 0 or v<0: return 0 d = [ 0 for _ in range(int(v)+1) ] d[0] = 1 for i in range(len(nums)): for j in range(int(v),nums[i]-1,-1): d[j] += d[j-nums[i]] print(d) return d[int(v)]
|