Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Your function should return length = |
|
public int removeDuplicates(int[] A) {
|
|
|
|
Use two pointers, one head, one next. If A[head] == A[next], then move next forward. Otherwise, copy A[next] to A[head+1], then increment both head and next.
|
|