What if duplicates are allowed at most n times? is this ok?


  • 0
    T

    public int removeDuplicates_NDuplicates (int[] A,int count)
    {

    if(A.length <=count) return A.length;
    int id = 0;
    for(int i = 0; i < A.length; i++) 
    {
    	if((i+count)>=A.length
    	   ||((i+count)<A.length&&A[i+count] != A[i])
    			)
    	{
    		A[id++]=A[i];
    	}
    }
    return id;
    

    }


Log in to reply
 

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