735. Move All Zeros to End (Recursive)

EasyRecursionRecursion

Given an integer array nums, move all 0s to the end of the array while maintaining the relative order of the non-zero elements. Return the resulting array. You must implement the operation recursively.

Input: An integer array nums.

Output: Return the modified array as [v1,v2,...].

Examples

Example 1
Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
Explanation: Non-zeros 1, 3, 12 keep order; zeros pushed to end.
Example 2
Input: [0,0,1]
Output: [1,0,0]
Explanation: 1 moved to front, zeros to end.
Example 3
Input: [1,2,3]
Output: [1,2,3]
Explanation: No zeros to move.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →