1def can_partition(nums):
2 total = sum(nums)
3 if total % 2:
4 return False
5 target = total // 2
6 dp = [False] * (target + 1)
7 dp[0] = True
8 for num in nums:
9 for current in range(target, num - 1, -1):
10 if dp[current - num]:
11 dp[current] = True
12 return dp[target]