leetcode-----80. 删除排序数组中的重复项 II

代码

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int k = 0;
        for (auto x: nums) {
            if (k < 2 || (nums[k - 1] != x || nums[k - 2] != x)) nums[k++] = x;
        }
        return k;
    }
};
posted @ 2020-07-14 21:35  景云ⁿ  阅读(82)  评论(0编辑  收藏  举报