Skip to content

Latest commit

 

History

History
25 lines (23 loc) · 620 Bytes

删除排序数组中的重复项.md

File metadata and controls

25 lines (23 loc) · 620 Bytes

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)$。