283. Move Zeros
Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]Input: nums = [0]
Output: [0]class Solution {
public void moveZeroes(int[] nums) {
int zeros = 0;
int j=0;
for(int i=0; i<nums.length; i++){
if(nums[i] == 0) zeros++;
else nums[j++] = nums[i];
}
while(j < nums.length) nums[j++] = 0;
}
}Last updated