Keep One of Each
You are given a list of integers nums, sorted from smallest to largest, in which some values may repeat. Return the list with one copy of each value, still in order.
Examples
nums = [1, 1, 2, 3, 3, 3, 7] → [1, 2, 3, 7]
nums = [4, 4, 4] → [4]
nums = [-2, 0, 5] → [-2, 0, 5]Constraints
- Between 0 and 10,000 numbers, sorted, each between -1,000,000,000 and 1,000,000,000.
- Aim for O(n) time and O(1) memory beyond the answer: the list is sorted, so a set is not needed.
Console
›Run to see what your code prints
Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.