JavaScript solution


  • 0
    L
    function moveZeroes(nums) {
      var idx = 0;
      for (var i = 0; i < nums.length; i++) {
        if (nums[i] !== 0) {
          nums[idx] = nums[i];
          nums[i] = idx === i ? nums[i] : 0;
          idx++;
        }
      }
    }

Log in to reply
 

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