leetcode/src/string_array/rotate.cpp
2024-03-26 19:18:25 +08:00

20 lines
318 B
C++

//
// Created by yangzuhao on 2024/3/26.
//
#include <queue>
#include "string_array.h"
namespace yaha {
void Array::rotate(std::vector<int> &nums, int k) {
int n = nums.size();
k = k % n;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
a[(i + k) % n] = nums[i];
}
nums = a;
}
}