js solution


  • 0
    R
    /**
     * @param {number[]} nums
     * @param {number} k
     * @return {void} Do not return anything, modify nums in-place instead.
     */
    var rotate = function(nums, k) {
        let n = nums.length;
        if (n === 0) return;
        k %= n;
        if (k === 0) return;
        nums.unshift(...nums.splice(n - k, k));
    };
    

Log in to reply
 

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