My solution in Java


  • 0
    C

    public class Solution {
    public int removeDuplicates(int[] nums) {
    int length= nums.length;
    for (int i=0;i<nums.length-1;i++){ //be careful of IndexOutOfBoundaryException
    if (nums[i]==nums[i+1])
    length--;
    }
    return length;
    }
    }

    I tried it in my computer and it works, but in this system cannot pass judge. Don't know why.


  • 0
    X

    You should put all unique numbers in begin of array.


  • 0
    C

    Any example?
    I still not quite get it.


Log in to reply
 

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