Simple JS in place array shifting

  • 0

    Pop the tail off the array, push it to the front.

     * @param {number[]} nums
     * @param {number} k
     * @return {void} Do not return anything, modify nums in-place instead.
    var rotate = function(nums, k) {
        for(let i = 0; i < k; i++) {
            let thisNum = nums.pop();

Log in to reply

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