1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

int RemoveDuplicates(int A[], int n) 
{
    if (n<1)return 0;

    int i = 1;
    int j = 0;
    int val = A[j]; //init val with A[0];

    while(++j < n)
        if(val != A[j])
            val = A[i++] = A[j];

    return i;
}



#include "stdio.h"

int main(int argc, char** argv)
{
    int a[] = {-1,-1,2,2,3,3,3,5,5,5,5,5,7,7,7,7,7,7,7};

    int count = RemoveDuplicates(a, 19);

    for (int i = 0; i < count; ++i)
        printf("%d, ", a[i]);

    return 0;
}
View Program Text


Test Status