Remove Duplicates from Sorted Array

这道题的解法是一个类似反转链表的函数,没啥逻辑可讲属于要背的,下面是代码

class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums:
            return 0
        index = 0
        for i in xrange(len(nums)):
            if nums[index] != nums[i]:
                index += 1
                nums[index] = nums[i]
        return index + 1

results matching ""

    No results matching ""