Simple java solution


  • 1
    S
    public class Solution {
        public void moveZeroes(int[] nums) {
            int index = 0 ;
            for(int i = 0 ; i < nums.length; i++)
            {
    
                if (nums[i]!=0 )
                {
                    nums[index]=nums[i];
                    if(index!= i)
                    {
                        nums[i]= 0;
                    }
                    index++;
                }
            }
        }
    }

Log in to reply
 

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