123456789101112131415
// 要求冗余元素至多为N个。class Solution {public: int removeDuplicates(vector<int>& nums) { if (nums.size() < = N) return nums.size(); int index = N; for (int i = N; i < nums.size(); i++) { if (nums[index - N] != nums[i]) { nums[index++] = nums[i]; } } return index; }};