Remove Duplicates from Sorted Array
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.
Remove Duplicates from Sorted Array
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.
Example 1
Input: nums = [1,1,2] Output: 2
Example 2
Input: nums = [0,0,1,1,1,2,2,3,3,4] Output: 5
Show hint
Use two pointers: one to iterate through the array, another to track the position where unique elements should be placed.
Sign in to submit, save progress and mark problems as solved. You can still run your code.
Loading editor...
nums =
[1,1,2]
Expected
2