My Java Solution


  • 0
    L
    public class Solution {
        public void moveZeroes(int[] nums) {
            if(nums == null || nums.length == 0)
            	return;
            int behind = 0;
            int front = 0;
            while(front < nums.length){
            	if(nums[front] != 0){
            		nums[behind++] = nums[front++];
            	}
            	else {
            		front++;
            	}
            }
            while(behind < nums.length){
            	nums[behind++] = 0;
            }
        }
    }

Log in to reply
 

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