leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0080.cpp (377B)


      1 class Solution {
      2   public:
      3     int removeDuplicates(vector<int> &nums) {
      4         int k = 1;
      5         for (int i = 1; i < nums.size(); i++) {
      6             nums[k++] = nums[i];
      7             if (nums[i] == nums[i - 1]) {
      8                 while (++i < nums.size() && nums[i] == nums[k - 2])
      9                     ;
     10                 i--;
     11             }
     12         }
     13         return k;
     14     }
     15 };