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 2d0e0cc commit 4346096Copy full SHA for 4346096
typescript/0189-rotate-array.ts
@@ -0,0 +1,35 @@
1
+/**
2
+ Do not return anything, modify nums in-place instead.
3
+ */
4
+function rotate(nums: number[], k: number): void {
5
+ k = k % nums.length;
6
+ let l = 0;
7
+ let r = nums.length - 1;
8
+ while (l < r) {
9
+ let temp = nums[l];
10
+ nums[l] = nums[r];
11
+ nums[r] = temp;
12
+ l += 1;
13
+ r -= 1;
14
+ }
15
+
16
+ l = 0;
17
+ r = k - 1;
18
19
20
21
22
23
24
25
26
+ l = k;
27
+ r = nums.length - 1;
28
29
30
31
32
33
34
35
+}
0 commit comments