Skip to content

Commit

Permalink
删除排序数组中的重复项
Browse files Browse the repository at this point in the history
  • Loading branch information
money89757 committed Sep 25, 2018
1 parent ada66c7 commit 1f060a9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 算法/LeetCode/removeDuplicates.c
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;
}

0 comments on commit 1f060a9

Please sign in to comment.