My JavaScript Solution


  • 0
    Z

    /**

    • @param {number[]} nums

    • @return {void} Do not return anything, modify nums in-place instead.
      */
      var moveZeroes = function(nums) {
      if(nums === null )
      return nums;

      var noZeroIndex = 0;
      for( var i = 0 ; i < nums.length ; i++ ) {
      if(nums[i] !== 0) {
      if( noZeroIndex !== i) {
      nums[noZeroIndex] = nums[i];
      nums[i] = 0;
      }
      noZeroIndex ++;
      }
      }
      };

    • [list item](>! link url)


Log in to reply
 

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