-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path189.cpp
More file actions
34 lines (31 loc) · 721 Bytes
/
189.cpp
File metadata and controls
34 lines (31 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
Solution() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void rotate(vector<int>& nums, int k) {
k = k % nums.size();
vector<int> temp;
for (int i = nums.size() - k; i < nums.size(); i++) {
temp.push_back(nums[i]);
}
for (int i = 0; i < nums.size() - k; i++) {
temp.push_back(nums[i]);
}
nums = temp;
}
};
int main() {
Solution s;
vector<int> nums = {1, 2, 3, 4, 5, 6, 7};
s.rotate(nums, 3);
for (int i = 0; i < nums.size(); i++) {
cout << nums[i] << " ";
}
cout << endl;
return 0;
}