What is wrong with my code? (Python)

  • 0
    def removeDuplicates(self, A):
        if len(A)==0 or len(A)==1:
            return len(A)
        while i<len(A):
            if A[i]!=A[i-1]:
        return j

    Input: [1,1]

    Output: del, pop(), or remove() are not allowed.

    Expected: [1]

    I did not use del/pop/remove. I just use A[j: ] to shrink the list. Any one knows what's the problem?

  • 1

    You are not allowed to shrink the list. Instead you return the size of the list after duplicate items are "removed".

    See here if you are still confused what to return.

  • 0

    1337c0d3r gave the answer. You are not required to shrink the list A, just return the correct size for unique numbers. The OJ refused to accept any size modification of A.

Log in to reply

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