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

Warm-ups · 6 of 24

Move zeros to the end

Move every 0 to the end of the array while keeping the other numbers in their original order. Change nums in place.

Jump to the editor ↓

Examples

Input nums = [0, 1, 0, 3, 12]

Output nums becomes [1, 3, 12, 0, 0]

Input nums = [1, 2, 3]

Output nums stays [1, 2, 3]

📘 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?