26. 删除排序数组中的重复项

class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums oor len(nums) <= 1:
            return len(nums)
        count = 1
        for i in range(1,len(nums)):
            if nums[i] != nums[count-1]:
                nums[count] = nums[i]
                count += 1
        return count

class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums oor len(nums) <= 2:
            return len(nums)
        count = 2 # count是待修改的下标,i是检查的下标;一开始count=i=2;i和count-2对比;count之前是保留的数,count是待插入的位置;插入完了count和i都+1
        for i in range(2,len(nums)):
            if nums[i] != nums[count - 2]:
                nums[count] = nums[i]
                count += 1
        return count