题目::26. 删除有序数组中的重复项 - 力扣(LeetCode)
思路:只要不和前面的数一样就可以移动指针,进行赋值
代码:
class Solution {
public:int removeDuplicates(vector<int>& nums) {int slow = 0 ;for(int fast = 1; fast < nums.size(); fast++){if(nums[slow] != nums[fast]){slow++;nums[slow] = nums[fast];}}slow++;return slow;}
};
用时: