Javascript easy to understand


  • 0
    Q

    /**

    • @param {number[]} nums

    • @param {number} k

    • @return {void} Do not return anything, modify nums in-place instead.
      */
      var rotate = function(nums, k) {
      var n=nums.length;

      if(n===0||k===0) return;
      k%=n;
      for(var i=0;i<n-k;i++){
      nums.push(nums.shift());
      }
      };


Log in to reply
 

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