数组 26、27、80
2019-07-02 本文已影响0人
poteman
快慢指针,
fast指向当前处理的值
slow的值代表:遇到合法的值,将合法的值放在slow的位置。
- lc80
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums) <= 2:
return len(nums)
slow = 2
for fast in range(2, len(nums)):
if (nums[fast] == nums[slow-1]) and (nums[slow-1] == nums[slow-2]):
continue
else:
nums[slow] = nums[fast]
slow += 1
return slow