25. Remove Duplicates from Sorted Array

EasyArray

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. Then return the number of unique elements in nums. Consider the number of unique elements of nums to be k, to get accepted you need to change the array nums such that the first k elements of nums hold the unique elements in the order they were present initially.

Examples

Input: [0,0,1,1,1,2,2,3,3,4]

Output: [0,1,2,3,4]

Explanation: The five unique values, kept in order (k=5).

Constraints

  • 1 <= nums.length <= 3 * 10^4
  • -100 <= nums[i] <= 100
  • nums is sorted in non-decreasing order.
Loading...

Run checks all cases above. Submit evaluates all test cases.