Loading problem…
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
nums
k
// Example 1 let nums = [1,2,3,4,5,6,7]; rotate(nums, 3); // nums becomes [5,6,7,1,2,3,4] // Rotated right by 3: [1,2,3,4,5,6,7] → [5,6,7,1,2,3,4] // Example 2 let nums = [-1,-100,3,99]; rotate(nums, 2); // nums becomes [3,99,-1,-100]
3 hints available with Pro