My Javascript Solution


  • 0
    R
    var rotate = function(nums, k) {
        //generate array of what to move by splicing the array of the original array 
    	var arrayToMove = nums.splice(nums.length - k, k).reverse();
    	//For each item in the array to move add it to the top of the original
    	arrayToMove.forEach(function(integer){nums.unshift(integer)});
    };

Log in to reply
 

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