We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent de2c12e commit f46cec2Copy full SHA for f46cec2
Arrays/Rotate Array (LeetCode).cpp
@@ -0,0 +1,27 @@
1
+class Solution
2
+{
3
+ public:
4
+ void rotate(vector<int>& nums, int k)
5
+ {
6
+ int n = nums.size();
7
+ int start = n - k % n;
8
+ int remainder = k % n;
9
+ vector<int> v(n);
10
+
11
+ for(int i = 0; i < remainder; i++)
12
13
+ v[i] = nums[i + start];
14
+ }
15
16
+ for(int i = 0; i < start; i++)
17
18
+ v[i + remainder] = nums[i];
19
20
21
+ for(int i = 0; i < n; i++)
22
23
+ nums[i] = v[i];
24
25
26
+};
27
0 commit comments