class Solution { public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if (n == 0) return 0; int p=0; int q=1; while(q<n) { if(A[q]==A[p]) { q++; } else { p++; A[p] = A[q]; q++; } } return (p+1); } };
Attention: edge case!!!
input | output | expected | |
---|---|---|---|
[] | [0] | [] |
Wrong!
|