题目:
题解:
func canPartition(nums []int) bool {n := len(nums)if n < 2 {return false}sum, max := 0, 0for _, v := range nums {sum += vif v > max {max = v}}if sum%2 != 0 {return false}target := sum / 2if max > target {return false}dp := make([]bool, target+1)dp[0] = truefor i := 0; i < n; i++ {v := nums[i]for j := target; j >= v; j-- {dp[j] = dp[j] || dp[j-v]}}return dp[target]
}