因为是排序数据,所以极其简单:
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
if nums:
k = 0
for num in nums[1:]:
if num != nums[k]:
k += 1
nums[k] = num
return k + 1
else:
return 0