0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution: def canPartition(self, nums: List[int]) -> bool: target = sum(nums)/2 d = [ 0 for _ in range(int(target+2))] print(target) for i in range(len(nums)): for j in range(int(target+1),nums[i]-1,-1): d[j] = max( d[j], d[j-nums[i]]+nums[i] ) for _ in d: if _==target: return True return False
|