The problem. Given an integer array nums, move every 0 to the end while keeping the relative order of the non-zero elements. Do it in place, without returning a new array.
Input: nums = [0, 1, 0, 3, 12]
Output: [1, 3, 12, 0, 0]
Input: nums = [0]
Output: [0]Two rules make this more than a sort: the non-zero values must keep their original order (1, then 3, then 12), and the work must happen inside the same array.
Free account
Sign up to read the rest of this lesson: 5 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come