Update Leetcode 题解.md

This commit is contained in:
aaaaaabiao 2019-01-25 11:53:01 +08:00 committed by GitHub
parent 7fd67bd80b
commit 4643cdcc9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3050,7 +3050,6 @@ public boolean canPartition(int[] nums) {
int W = sum / 2;
boolean[] dp = new boolean[W + 1];
dp[0] = true;
Arrays.sort(nums);
for (int num : nums) { // 0-1 背包一个物品只能用一次
for (int i = W; i >= num; i--) { // 从后往前,先计算 dp[i] 再计算 dp[i-num]
dp[i] = dp[i] || dp[i - num];