Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
Example:
1 | Input: [0,1,0,3,12] |
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
我的解决思路如下:
便利向量nums, 统计有多少0值,将0值数删除,最后补0
1 | class Solution { |