Why just replace first part of the array while there are still duplicates?


  • 0
    W

    I do not understand the meaning of this question, it not only ask for the new length, but also check if the array is changed. But it only check part of the array.

    For example: [1,1,1,2,2,2] =>[1,2,1,2,2,2] and l=2
    OJ only check the length and the first part of the array. While the question is asking:

    "remove the duplicates in place such that each element appear only once and return the new length.
    Given input array A = [1,1,2],
    Your function should return length = 2, and A is now [1,2]."

    For [1,1,1,2,2,2] =>[1,2,1,2,2,2], the array is not completed changed, there are still duplicates....
    It is very confusing and misleading...

    Maybe the people who create this question means that he has a method that can get a sub-array with the length given, but for us, we do not know how will he check the array if he do not tell us.


  • 1

    Yes, you should just worry to remove the duplicates from the first part of the array, up to the new computed length with no duplicates.

    The online judge will check just if the elements up to that length have no duplicates, ignoring the part of the array after the new length.


  • 0
    W

    Thank you very much!!


  • 0

    You are welcome! :)


Log in to reply
 

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