Java esay solution using stack


  • -1
    J
    public class Solution {
    public void moveZeroes(int[] nums) {
        Stack<Integer> stack = new Stack<>();
    	for(int x:nums){
    		if(x!=0){
    			stack.push(x);
    		}
    	}
    	while(stack.size()<nums.length){
    		stack.push(0);
    	}
    	
    	for(int i = nums.length-1;i>=0;i--){
    		nums[i] = stack.pop();
    	}
    }
    

    }


Log in to reply
 

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