java solution


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

Log in to reply
 

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