Why the running result does not match between my laptop and OJ on the same code?


  • 0
    C

    On Problem: Remove duplicates on Sorted Array
    Here is my code

    int removeDuplicates(int A[], int n) {	
    	 	int length = n;
    	 	int offset = 0;
    	 	for(int i=0; i<length; i++) {
    	 		A[i] = A[i+offset];
    	 		while(A[i] == A[i+offset+1]) {
    	 			offset ++;
    	 		}
    	 		length = n - offset;
    	 	}
    	 	return length;
    	 }
    

    when input is {-3. -1. 0, 0}, I get {-3, -1, 0} on laptop but OJ claims WA with the output {-3, -1}


  • 0
    Z

    it seems out of boundary when i = 4 and offset = 1 while (A[i] == A[i + offset + 1]


Log in to reply
 

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