O(1)内存消耗:(当然了,用set直接去掉重复元素不用写)
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if len(nums)==0:
return 0
i = 0
for j in range(1,len(nums)):
if nums[j]!= nums[i]:
i = i+1
nums[i] = nums[j]
return i+1
网友评论