https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/submissions/
重点这是一个排序数组
/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function(nums) {
let slow = 0;
for (let fast = 1; fast < nums.length; fast++) {
if (nums[slow] !== nums[fast]) {
slow++
nums[slow] = nums[fast]
}
}
return slow + 1
};
时间复杂度:$O(n)$. 空间复杂度:$O(1)$。