All problems

Remove Duplicates from Sorted Array

Easy · two pointers

A librarian keeps a catalogue of book numbers in nums, already sorted from smallest to largest. Some numbers were entered several times by mistake.

Return the catalogue with each number kept once, still in ascending order.

Examples

Example 1

Input: nums = [1, 1, 2, 2, 2, 5]

Output: [1, 2, 5]

Each distinct number appears once, in ascending order.

Example 2

Input: nums = [4, 4, 4]

Output: [4]

Example 3

Input: nums = [-3, 0, 7]

Output: [-3, 0, 7]

Constraints