Got the wrong answer while the code works well on my computer


  • 0
    A
    int removeDuplicates(int A[], int n) {
       if(n<=2)
    		return n;
    	int count = 0;
    	int i = 0;
    	while(i<n)
    	{
    		int j = i+1;
    		while(A[j]==A[i])
    			j++;
    		A[count] = A[i];
    		count++;
    		i = (j==i+1)?i+1 : j-1;
    	}
    	return count;
    }
    

    In this case ,the system got the wrong answer

    Input:	[0,0,0,0,0]
    Output:	[0]
    Expected:[0,0]
    

    But on my computer, I got [0,0] exactly.


Log in to reply
 

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