Remove Duplicates from Sorted Array

Easy

Given an integer array nums sorted in non-decreasing order, remove the duplicates so each unique element appears only once. Return the array of unique values, maintaining their relative order.

Example 1

removeDuplicates()
Input
nums = [1,1,2]
Output
[1,2]

Example 2

removeDuplicates()
Input
nums = [0,0,1,1,1,2,2,3,3,4]
Output
[0,1,2,3,4]
Constraints
1 <= nums.length <= 3 * 10^4
nums is sorted in non-decreasing order.

Topics

ArraysTwo Pointers

Implement removeDuplicates in the editor and return the answer — printing it is never graded.