Search for a command to run...
You are given an array of integers nums
You are also given an integer k
Your task is to rotate the array to the right by k steps
Each step moves elements one position to the right
The last element moves to the front
Input:
nums = [1, 2, 3, 4, 5, 6, 7]
k = 3Output:
[5, 6, 7, 1, 2, 3, 4]You must modify the array in-place
Do not use extra space (O(1) space only)
1 β€ nums.length β€ 10β΅
-10βΉ β€ nums[i] β€ 10βΉ
0 β€ k β€ 10βΉ
Example 1
[1, 2, 3, 4, 5, 6, 7], 3[5,6,7,1,2,3,4]Example 2
[1, 2], 0[1,2]Example 3
[1, 2, 3], 3[1,2,3][1, 2, 3, 4, 5, 6, 7], 3
[5,6,7,1,2,3,4]