首页 > 代码库 > 080. Remove Duplicates from Sorted Array II

080. Remove Duplicates from Sorted Array II

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

 

080. Remove Duplicates from Sorted Array II