-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ada66c7
commit 1f060a9
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
|
||
int removeDuplicates(int *nums, int numsSize) | ||
{ | ||
if(nums == NULL || numsSize == 0) | ||
return 0; | ||
|
||
int right = 0,i; | ||
for(i = 0; i < numsSize; i++) | ||
{ | ||
if(right < 2 || nums[right - 2] != nums[i]) | ||
nums[right++] = nums[i]; | ||
} | ||
return right; | ||
} | ||
|
||
int main(int argc, const char *argv[]) | ||
{ | ||
int nums[] = {0,0,1,1,1,1,2,3,3}; | ||
int a,i; | ||
a = removeDuplicates(nums,9); | ||
printf("a = %d\n",a); | ||
|
||
for(i = 0; i < a ; i++) | ||
{ | ||
printf("nums[%d] = %d\n",i,nums[i]); | ||
} | ||
return 0; | ||
} |