leetcode_打卡10
题目:283. 移动零
思路:双指针,数值互相交换,不是复制覆盖
代码:
class Solution {
public void moveZeroes(int[] nums) {
int n=nums.length;
int l=0,r=0;
while(r<n){
if(nums[r]!=0){
swap(nums,l,r);
l++;
}
r++;
}
}
public void swap(int[] nums,int l,int r){
int temp=nums[r];
nums[r]=nums[l];
nums[l]=temp;
}
}
标签:10,nums,int,while,打卡,leetcode
From: https://www.cnblogs.com/ZLey/p/17339946.html