删除排序数组中的重复项

比较简单的题目: 

给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。

不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int i=0;
        int j=0;
        while(j < nums.size()) {
            auto e = nums[j++];            
            if(i ==0 || nums[i-1] != e ) {
                nums[i] = e;
                i++;
            }            
        }        
        return i;
    }
};
The Safest Way to Get what you Want is to Try and Deserve What you Want.
原文地址:https://www.cnblogs.com/Shinered/p/11277909.html