java code. Wrong Answer?


  • 0
    E
    public int removeDuplicates(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        int now = nums[0];
        int num = 1;
        for (int i = 1; i < nums.length; i++) {
            if (now == nums[i]) continue;
            num++;
            now =nums[i];
        }
        return num;
    }
    

    where is my code's wrong?

    Input:
    [1,1,2]
    Output:
    [1,1]
    Expected:
    [1,2]


Log in to reply
 

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