Remove Duplicates from Sorted Array in Java
Say you have an array of primitive integers and you want to remove all duplicates.
You can find out how many non-duplicate integers are in the array with this method:
Because we pass the nums
array in as a reference, and modify the variable in-place with no additional space, you could just continue using it as is.
Your other option could be to return the nums
variable at the end if you wanted the actual duplicates removed out: