删除有序数组中的重复项
https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/ (opens new window) 需要注意的点
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) < 1:
return 0
slow = 0
fast = 0
while fast < len(nums):
if nums[slow] != nums[fast]:
# 符合条件 slow增加, 条件是 slow 跟fast相等
slow += 1
nums[slow] = nums[fast]
# fast 总是增加
fast += 1
return slow+1