LeetCode 26 Remove Duplicates from Sorted Array

LeetCode  26 Remove Duplicates from Sorted Array

 

与27题类似 http://www.cnblogs.com/walker-lee/p/4994950.html

 

int removeDuplicates(int* nums, int numsSize) {
    if(numsSize<=0)
        return 0;
    if(numsSize==1)
        return 1;
    int n=0;
    for(int i=1;i<numsSize;i++)
    {
        if(nums[i]!=nums[n])
            nums[++n]=nums[i];
    }
    return n+1;
}

 

posted @ 2015-11-25 16:06  Walker_Lee  阅读(127)  评论(0编辑  收藏  举报