Record my 1ms Java solution


  • 0
    H
    public class Solution {
        public void moveZeroes(int[] nums) {
            if(null == nums || nums.length==0) return ;
            int zeroIdx=-1;
            for(int i=0;i<nums.length;i++) {
                int t = nums[i];
                if(t != 0){
                    if(zeroIdx>=0){
                        nums[zeroIdx]=t;
                        zeroIdx+=1;
                        nums[i]=0;
                    }
                }else{
                    if(zeroIdx==-1) zeroIdx = i;
                }
            }
        }
    }
    

Log in to reply
 

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