We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 42ffea3 commit 285d25dCopy full SHA for 285d25d
README.md
@@ -26,7 +26,7 @@
26
27
## Week 3 🚧
28
29
-Coming Soon...
+1. [Rotate Array](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/561/week-3-october-15th-october-21st/3496/) ➡️ [CPP Solution](Week3/rotate.cpp)
30
31
## Week 4 🚧
32
Week3/rotate.cpp
@@ -0,0 +1,24 @@
1
+class Solution {
2
+private:
3
+ void reverse(vector<int>& nums, int start, int end) {
4
+ int tmp;
5
+
6
+ while(start < end) {
7
+ tmp = nums[start];
8
+ nums[start] = nums[end];
9
+ nums[end] = tmp;
10
11
+ start++;
12
+ end--;
13
+ }
14
15
+public:
16
+ void rotate(vector<int>& nums, int k) {
17
+ int n = nums.size();
18
+ k = k % n;
19
20
+ reverse(nums, 0, n - 1);
21
+ reverse(nums, 0, k - 1);
22
+ reverse(nums, k, n - 1);
23
24
+};
0 commit comments