Remove Duplicates from Sorted Array

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int length = nums.size();
        int size= 0;
        if(length<=1)
        return length;
        for(int i= 1;i<length;i++)
        {
            if (nums[size]!= nums[i])
           { size++;
            nums[size] = nums[i];
           }
        }
       return size+1;
       
    }
};

posted @ 2015-12-10 15:51  雪之灵  阅读(110)  评论(0)    收藏  举报