Simple Java solution


  • 0
    B
    public class Solution {
    public void moveZeroes(int[] nums) 
    {
        Integer zeroIndex = null;
        
        for (int i=0;i<nums.length;i++)
        {
            if (nums[i] != 0 && zeroIndex != null)
            {
                nums[zeroIndex++] = nums[i];
                nums[i] = 0;
            }
            else if (nums[i] == 0 && zeroIndex == null)
                zeroIndex = i;
        }
    }
    

    }


Log in to reply
 

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