My python3 solution

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

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.