class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int idx = 1;
for (int i = 1; i < nums.size(); i++) {
if (nums[i] == nums[i - 1]) continue;
nums[idx++] = nums[i];
}
return idx;
}
};
Time Complexity: O(n)
Space: O(1)
沒特別想說的