remove duplicates from sorted array

https://leetcode.com/problems/remove-duplicates-from-sorted-array/

https://www.youtube.com/watch?v=kdAiCZQVuvI

code


class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if(nums.size() == 0)
        {
            return 0;
        }

        int prev = 0;
        for(int i = 1; i<nums.size(); i++)
        {
            if(nums[i] != nums[prev])
            {
                nums[++prev] = nums[i];
            }
        }

        return prev+1;
    }
};

results matching ""

    No results matching ""