[LeetCode] Rotate Array

189. Rotate Array

Given an array, rotate the array to the right by k steps, where k is non-negative.

1
2
3
4
5
6
class Solution {
public:
void rotate(vector<int>& nums, int k) {
std::rotate(nums.begin(), nums.end() - (k % nums.size()), nums.end());
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2021/04/24/PS/LeetCode/rotate-array/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.