- Notifications
You must be signed in to change notification settings - Fork 117
/
Copy path80.c
39 lines (34 loc) · 856 Bytes
/
80.c
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
31
32
33
34
35
36
37
38
39
#include<stdio.h>
intremoveDuplicates(int*nums, intnumsSize) {
if (nums==NULL||numsSize==0) return0;
intstoreIndex=0;
inti=0;
while (i<numsSize) {
intcount=1;
while (i<numsSize-1&&nums[i] ==nums[i+1]) {
i++;
count++;
if (i >= numsSize) goto OUT;
}
if (count >= 2) {
nums[storeIndex++] =nums[i];
nums[storeIndex++] =nums[i];
}
else {
nums[storeIndex++] =nums[i];
}
i++;
}
OUT:
returnstoreIndex;
}
intmain() {
intnums[] = { 1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5 };
intnew_len=removeDuplicates(nums, sizeof(nums) / sizeof(nums[0]));
inti;
for (i=0; i<new_len; i++) {
printf("%d ", nums[i]);
}
printf("\n");
return0;
}