Ninety-three days: force buckle 189, rotation array

Address: leetcode-cn.com/problems/ro…

1. Unshift and pop

2. Reserve reversal

var rotate = function(nums, k) {
  const n = nums.length;
  for(let i = 0; i < k; i++)
  {
    nums.unshift(nums[n - 1]);
    nums.pop();
  }
  return nums;
};
Copy the code

Execution time: 132 ms, beating 26.47% of all JavaScript commits

Memory consumption: 38.8 MB, beating 61.70% of all JavaScript commits