JavaScript O(1) time and O(1) space solution


  • 0
    var rotate = function(nums, k) {
        const len  = nums.length;
        k = k % len;
        var subAry = nums.splice(len-k, k);
        nums.unshift(...subAry);
    };

Log in to reply
 

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