leetcode 26. 删除排序数组中的重复项 (python)

class Solution:
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        
        num_former_number = len(nums)
        
        if num_former_number <1:
            return 0
        else:
            i= 1
            num_new_number = 1
            num_new_index = 1  #  the index where next new number puts here
            former_number = nums[0]
            for i in range(num_former_number):
                if nums[i] != former_number:
                    nums[num_new_index] = nums[i]
                    num_new_number = num_new_number + 1
                    former_number = nums[i]
                    num_new_index += 1
            return num_new_number
            

 

你可能感兴趣的:(leetcode 26. 删除排序数组中的重复项 (python))