DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Rotate Array - I

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var rotate = function(nums, k) {
   if(k > nums.length)
        k = k - nums.length;

    nums.unshift(...nums.splice(nums.length - k, k))


    return nums
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)