Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | 4x 2x 2x 2x 2x 2x 2x | export default function rotate(nums: number[], k: number): number[] {
if (nums.length < 2 || k === 0)
return nums
const rotate = k % nums.length
const rotatedNums = [
...nums.slice(nums.length - rotate),
...nums.slice(0, nums.length - rotate),
]
nums.splice(0)
nums.push(...rotatedNums)
return nums
}
|