Share my c solution,just need a flag compared with sorted Array I


  • 0
    F

    int removeDuplicates(int A[], int n) {
    int i,lenth=0;
    int flag=0;
    if(A==NULL||n<=0)return 0;
    for(i=0;i<n-1;i++){
    if(A[i]!=A[i+1]){
    A[lenth]=A[i];
    lenth++;
    flag=0;
    }
    else{
    if(flag==0){
    A[lenth]=A[i];
    lenth++;
    flag=1;
    }
    }
    }
    A[lenth]=A[i];
    lenth++;
    return lenth;

    }


Log in to reply
 

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