0026. Remove Duplicates from Sorted Array
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
// fast and slow start from 0
// fast go first
// if nums[fast] != nums[slow], slow++ and swap
// return slow
int fast = 1, slow = 0;
// 0 1 0 1 1 2 2 3 3 4
// 0 1 2 1 1 0 2 3 3 4
// s f
for(; fast < nums.size(); fast++) {
if(nums[fast] != nums[slow]) {
slow++;
nums[slow] = nums[fast];
}
}
return slow + 1;
}
};