1 class Solution { 2 public: 3 int removeDuplicates(vector<int>& nums) { 4 if (nums.size() == 0) return 0; 5 int j = 0; 6 for (int i = 1; i < nums.size(); ++i) { 7 if (nums[i] != nums[j]) { 8 nums[++j] = nums[i]; 9 } 10 } 11 return j + 1; 12 } 13 };
时间: 2024-10-27 02:59:01