Why {2, 2, 3, 5}, {1, 3, 4, 4} expected true? I don't think they can be partitioned to two sets.
Please correct me if my understanding is wrong.
To pass all test cases, below very simple solution is just OK:
public boolean canPartition(int[] nums) {
if(nums == null)
return false;
int sum = 0, max = 0;
for (int i: nums) {
sum += i;
if(i > max)
max = i;
}
if(sum % 2 != 0)
return false;
return max <= sum/2;
}
But like I said, for some test cases, I think the result is just wrong.
@Xiuwei looks like the test cases have been updated, expected answers are now correct for the two examples you provided.