type
status
date
slug
summary
tags
category
icon
password
题目:
给定一个数组
nums
,编写一个函数将所有 0
移动到数组的末尾,同时保持非零元素的相对顺序。请注意 ,必须在不复制数组的情况下原地对数组进行操作。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/SNJvJP 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
示例 1:
示例 2:
提示:
1 <= nums.length <= 104
231 <= nums[i] <= 231 - 1
思路:
- 两两交换,把0换到最后
代码:
结果:

image-20220302140650471