What's the valid format for output (Python)


  • 1
    P

    In the beginning I came up with a quick solution:

    A = list(set(A))
    return len(A)
    

    and then I realized it violated the 'extra space' limitation, and then I started to implement another solution and didn't pass. I would like to double check the expected output here.

    For instance, if the input is [1,2,2,5,5,5,6], the expected output would be [1,2,5,6,None,None,None]?
    Or [1,2,5,6] would be just fine (but looks like it won't happen because we cannot invoke remove() and pop() and del)?

    Thanks for any feedback.


  • 0
    P

    By the way, is [1,2, None, 5, None, None,6] valid as the output in this case? I don't get enough clues from the description in the problem...


  • 0
    R

    Apparently you are required to overwrite the initial segment of the vector with the shortened array, and return the length of the shortened array.

    Judging from the incomprehensible error messages about lines not visible in my code, it looks like they use the number n you return to look at the initial segment A[:n]. Apparently you return 0 for input [].


  • 0
    P

    Thanks, I figured it out.


Log in to reply
 

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