C++ in 5 lines.


  • 0
    L
    int removeDuplicates(vector<int>& nums) {
        int i = 0;
        for (int num: nums)
            if (i < 2 || num != nums[i-2])
                swap(nums[i++], num);
        return i;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.