很简单。
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; } };
很简单。
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; } };
转载于:https://www.cnblogs.com/travelller/p/9475913.html