The requirement is to return the new length, not return a new array. So no new array allocation is needed.
Update:
Sorry, my fault, the above answer is not complete.
You don't need to re-size the array. After removing the duplicates, just leave the rest slots as they are.
E.g., [1, 1, 2]
becomes [1, 2, 2]
, and return 2.
If you want to prevent loitering, you can set the rest to 0. But this is not necessary to pass the online judge.