0ms O(n) Java solution


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

    }


Log in to reply
 

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