Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

283. Move Zeroes #83

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

public class Solution { public void moveZeroes(int[] nums) { int count = 0; for(int i = 0; i < nums.length; i++) { if(nums[i] == 0) count++; } int j = 0; for(int i = 0; i < nums.length; i++) { if(nums[i] != 0) { nums[j] = nums[i]; j++; } } int n = nums.length-1; while(count != 0) { nums[n] = 0; n--; count--; } } }