- //right指向待处理序列的首部
- //left指向处理后序列的尾部
-
- class Solution {
- public void swap(int[] nums, int left, int right){
- int tmp = nums[left];
- nums[left] = nums[right];
- nums[right] = tmp;
- }
- public void moveZeroes(int[] nums) {
- int n = nums.length;
- int left = 0;
- int right = 0;
- while(right < n){
- if(nums[right] != 0){
- swap(nums, left, right);
- left++;
-
- }
- right++;
- }
- }
-
- }