Android & iPhone apps are coming soon. Log in for a plan and reminders made for you →

Warm-ups · 7 of 24

Remove duplicates from a sorted array

The array is sorted. Remove the duplicates in place so each value appears once at the front, and return how many unique values there are.

Jump to the editor ↓

Examples

Input nums = [1, 1, 2]

Output 2

The front of nums becomes [1, 2, …].

Input nums = [0, 0, 1, 1, 1, 2, 2, 3, 3, 4]

Output 5

📘 New to this? Two pointers moving the same way explains the idea in a few minutes.

Solved it? The same idea on LeetCode: try it there ↗

Your code

Tab indents · ⌘/Ctrl+Enter runs · Esc leaves the editor

Stuck?