My beats 99.09 % cpp solution


  • 0
    W

    My beats 99.09 % cpp solution

    int removeDuplicates(vector<int>& nums) {
            if (nums.size() <= 1)
                  return nums.size();
            int setIdx = 1;
            for (int i = 1; i < nums.size(); ++i) {
                if (nums[i] != nums[i-1]) {
                    nums[setIdx] = nums[i];
                    ++setIdx;
                }
            }
            nums.resize(setIdx);
            return nums.size(); 
        }
    

Log in to reply
 

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