class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if (nums.empty())
return 0;
int pre = 0, cur = 0, n = nums.size();
while (cur<n){
if (nums[pre] == nums[cur]){
cur++;
}else{
nums[++pre] = nums[cur++];
}
}
return pre + 1;
}
};
26. 删除排序数组中的重复项
最新推荐文章于 2020-01-04 14:06:29 发布