nums
.false
as we cannot partition the array into two subsets with equal sum.dp
with a size of half_sum + 1
, where half_sum
is half of the total sum. Set dp[0]
to true
as a subset with sum 0
is always possible (empty subset).half_sum
to the number itself.dp[j]
to true
if dp[j]
is true
or if dp[j - num]
is true
, where num
is the current number in the array.dp[half_sum]
is true
, return true
, indicating that we can partition the array into two subsets with equal sum.dp[half_sum]
is false
, return false
.