← 返回 meta 的题目列表Rotate Array
类型:online_judge
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
Input
An integer array nums.
An integer k representing the number of rotations.
Output
The array after k rotations.
Example
Input: nums = [1, 2, 3, 4, 5, 6, 7], k = 3
Output: [5, 6, 7, 1, 2, 3, 4]
Input: nums = [-1, -100, 3, 99], k = 2
Output: [3, 99, -1, -100]
Constraints
Try to use O(1) extra space.
Example
Input
[1,2,3,4,5,6,7]
3