LeetCode 26. Remove Duplicates from Sorted Array

很简单。

class Solution {
public:
    int removeDuplicates(vector<int>& a) {
        int n=a.size();
        if (!n) return 0;
        int i=0,j=1;
        while(j<n){
            if(a[j]>a[i]) {a[++i]=a[j];j++;}
            else j++;
        }
        while(a.size()>i+1) a.pop_back();
        return i+1;
    }
};

 

posted @ 2018-08-14 17:17  Travelller  阅读(76)  评论(0编辑  收藏  举报