[Need help]Super wired test cases, are there WRONG test cases????????


  • 0

    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.


  • 0

    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.


  • 0
    F

    @Xiuwei looks like the test cases have been updated, expected answers are now correct for the two examples you provided.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.