Simple JAVA Solution-363 ms


  • 0
    C
    public int removeDuplicates(int[] A) {
    if(A.length==0||A.length==1) return A.length;
    int curr=0, x=1;
    while(curr<A.length&&x<A.length){
        if(A[curr]==A[x]){
            x++;
        }else{
        A[++curr]=A[x++];
        }
    }
    return curr+1;}

Log in to reply
 

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