题解 | #移动 0#
移动 0
https://www.nowcoder.com/practice/102586387caa4afcbad6f96affce9780
import java.util.*;
public class Solution {
public int[] moveZeroes (int[] nums) {
// write code here
int[] ret = new int[nums.length];
int i = 0;
int j = 0;
while(i < nums.length){
while(i < nums.length && nums[i] == 0){
i++;
}
if (i == nums.length){
break;
}
ret[j++] = nums[i++];
}
return ret;
}
}
查看22道真题和解析