0026.cpp (238B)
1 class Solution { 2 public: 3 int removeDuplicates(vector<int> &nums) { 4 int j = 1; 5 for (int i = 1; i < nums.size(); i++) { 6 if (nums[i - 1] != nums[i]) nums[j++] = nums[i]; 7 } 8 return j; 9 } 10 };