思路: p指向[0]待插入位置 q指向[1]开始遍历位置,如果[q]!=[p]则q位置的值放到p+1位置 p++,否则q++
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n = nums.size(), p = 0;
for (int i = 1; i < n; ++i) {
if (nums[i] == nums[p]) continue;
else {nums[p + 1] = nums[i]; p++;}
}
return p + 1;
}
};