This input "-3,-3,-2,-1,-1,0,0,0,0,0"

gets 7 returned and a[] = {-3,-3,-2,-1,-1,0,0} on my local PC,

while OJ gets 6 returned and a[] = {"-3,-3,-2,-1,-1,0}.

My code is like below.

class Solution {

public:

int removeDuplicates(int a[], int n) {

int dup = 0;

int dupSum = 0;

bool flag[1024] = {0};

for(int i = 1; i < n; i++)

{

while(a[i] == a[i-1])

{

dup++;

if(dup >= 2)

{

flag[i] = 1;

dupSum ++;

}

i++;

}

dup = 0;

}

int ret = n - dupSum;

int idx1 = 0;

while(flag[idx1] == 0)

idx1++;

for(int i = 0; i < ret; i++)

{

while(flag[idx1] == 1)

idx1++;

if(flag[i] == 1)

{

a[i] = a[idx1];

flag[idx1] = 1;

}

}

return ret;

}

};

Any advice?Thx!