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 };
时间: 2024-11-10 14:06:15