Problem
You get an integer array nums. Move every 0 to the end of nums. The items that are not 0 must keep their order.
Change nums in place, without a copy of the array. The function returns nothing.
Example 1
- Input:
- nums = [0,4,0,7,2]
- Output:
- [4,7,2,0,0]
Example 2
- Input:
- nums = [-3,0,9]
- Output:
- [-3,9,0]
Example 3
- Input:
- nums = [5,0,0]
- Output:
- [5,0,0]
- Explanation:
- The zeros are already at the end, so
numsdoes not change.
Constraints
- 1 <= nums.length <= 10^4
- -2^31 <= nums[i] <= 2^31 - 1
Follow-up
Find a solution that writes to the array as few times as possible.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- 3Sum
Coding · Array · Sorting · Two Pointers
- 3Sum Closest
Coding · Array · Sorting · Two Pointers
- 4Sum
Coding · Array · Sorting · Two Pointers
- Advantage Shuffle
Coding · Array · Greedy · Sorting
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Meta
Leetcode 283. Move Zeroes
Reported Jan 30, 2025 · 2 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 283. Move Zeroes
Reported Apr 3, 2026 · 2 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 8 records
Amazon
Move Zeroes
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 72. This is not an interview probability.
View sourceAmazon
Move Zeroes
Reported date not specified · Source window: 3mo