Is testcase wrong?


  • -1
    G
    public int removeDuplicates(int[] nums) {
        if(nums.length <= 1) return nums.length;
            int ret = 1;
            int num = nums[0];
    	for(int i = 1; i < nums.length; i++)  {
    	    if(nums[i] != num) {
    	        num = nums[i];
    		ret ++;
    	    }
    	}
    	return ret;
    }
    

    can't pass:
    Input:[1,1,2]
    Output:[1,1]
    Expected:[1,2]

    but,is this case's Output:2,Expected:2


Log in to reply
 

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