c++ solution (13 ms)


  • 0
    class Solution {
    public:
      int removeDuplicates(vector<int>& nums) {
        if (nums.size() == 0) return 0;
        int i = 1;
        while (i < nums.size()) {
          if (nums[i] == nums[i - 1]) i++;
          while (nums[i] == nums[i - 1] && i < nums.size()) nums.erase(nums.begin() + i);
          i++;
        }
        return nums.size();
      }
    };
    

Log in to reply
 

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