O(n) Python solution


  • 0
    T
    class Solution(object):
        def removeDuplicates(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            index = 0
            length = len(nums)
            if length < 2:
                return length
            for i in range(1,length):
                if nums[index] != nums[i]:
                    index += 1
                    nums[index] = nums[i]
            index += 1
            return index

Log in to reply
 

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