Given an array of integers nums and a non-negative integer k, rotate the array to the right by k steps and return the result.
Rotating to the right by 1 step means the last element moves to the front. When k is greater than or equal to the array length, use k % length to determine the effective rotation.
For example, [1, 2, 3, 4, 5] rotated by 2 becomes [4, 5, 1, 2, 3].
nums = [1, 2, 3, 4, 5], k = 2[4, 5, 1, 2, 3]nums = [1, 2, 3], k = 4[3, 1, 2]nums = [1, 2, 3], k = 0[1, 2, 3]0 <= nums.length <= 10^4-10^9 <= nums[i] <= 10^90 <= k <= 10^5Run your code to see results
Use Cmd+Enter to run