【算法】删除排序数组中的重复项
- 双指针,快指针和慢指针,快指针遍历数组,慢指针将不重复的值记录在数组
- 时间复杂度 O(n)
- 空间复杂度 O(1)
class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ i = 0 j = 0 while j<len(nums): if nums[i] == nums[j]: j = j+1 else: i = i+1 nums[i] = nums[j] return i+1