Simplest Solution in cpp


  • 0
    F
    int removeDuplicates(int A[], int n) {
            if(n==0) return 0;
            if(n==1) return 1;
            int c=A[0];
            for(int i=1;i<n;i++){
                if(A[i]==c){
                    A[i]=999999999;
                }else{
                    c=A[i];
                }
            }
            int index=0,i;
            std::sort(A,A+n);
            for( i=0;i<n;i++){
                if(A[i]==999999999){
                    index=i;
                    break;
                }
    
            }
            return i;
        }

Log in to reply
 

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