1. 描述
- Given an integer array nums, move all 0’s to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of the array. - 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
2. 分析
本题思路与leetcode27 移除元素类似,相当于就地移除数组中所有的0后再将数组末尾部分赋值为0。
3. 代码
class Solution {
public void moveZeroes