This problem was tricky! You really need to understand English well and read the problem carefully.
At first I thought I just needed to return the length after deletion. But that’s not all – you also need to make sure the first length elements of array A are valid.
Got WA at first, then Accepted on the next try.
Here is the code:
| |
A better approach would be to use two pointers and swap elements with the end of the array.