Java Solution 0ms


  • 0

    public class Solution {
    public void moveZeroes(int[] nums) {
    int j=0,count=0;
    int len=nums.length-1;
    for(int i=0;i<nums.length;i++){
    if(nums[i]==0) count++;
    else nums[j++] =nums[i];
    }
    for(int k=len;k>(len-count);k--){
    nums[k]=0;
    }
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.