• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Remove Duplicates from Sorted Array II

    less than 1 minute read

    <-M 80> 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;
        }
    };
    

    Tags: Algorithms, C++, Leetcode

    Updated: June 24, 2022

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.