Leetcode's output doesn't match the output on my PC.

  • 1

    This is my code

    class Solution:
    # @param a list of integers
    # @return an integer
    def removeDuplicates(self, A):
        A = [A[i] for i in range(len(A)) if A[i] != A[i-1] or i == 0]
        return len(A)

    Leetcode gives it a test case as :input = [1,1,2]
    On my PC this code correctly output [1,2]
    But leetcode says the output is [1,1].

    Really weird.

  • 0

    Your code do not satisfy the rule of this question:

    Do not allocate extra space for another array, you must do this in place with constant memory.

    This expression allocates new space in memory. Then you lost the original ref of A, which is judged by the system.

    A = [x for x in A]

Log in to reply

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