my short python solution


  • -1
    G
    class Solution(object):
        def removeDuplicates(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if len(nums) < 2:
                return len(nums)
            i, j, cnt = 0, 1, len(nums)
            while j < cnt:
                if nums[i] != nums[j]:
                    nums[i+1] = nums[j]
                    i += 1
                j += 1
            return i+1
    

Log in to reply
 

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