C++ solution


  • 0
    X

    // LeetCode, Remove Duplicates from Sorted Array II
    class Solution {
    public:
    int removeDuplicates(vector<int>& nums) {
    if (nums.size() <= 2) return nums.size();
    int index = 2;
    for (int i = 2; i < nums.size(); i++){
    if (nums[i] != nums[index - 2])
    nums[index++] = nums[i];
    }
    return index;
    }
    };


Log in to reply
 

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