Java removes duplicate elements from the sorted array
@H_ 502_ 1 @ Title Description
Given a sorted array, remove the duplicate elements in the array, keep only one duplicate element, and return the new array length.
@H_ 502_ 1 @ requirement: do not allocate additional space to the array. You must use the constant memory size for in-situ operation.
For example, given the array a = [1,1,2], your function call must return the length length = 2, and a now becomes [1,2].
@H_ 502_ 1 @ input
A sorted array, such as [1,2].
@H_ 502_ 1 @ output
Returns the new length of the array, for example, length = 2.
@H_ 502_ 1 @ fast and slow pointer method
Set the fast pointer to traverse the array, and the slow pointer to the next bit of the non repeating element.
Animated presentation:
@H_ 502_ 1 @ extension
Removes duplicate elements from the sorted array and retains the specified number of bits.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.