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 e4338a9 commit a1b5494Copy full SHA for a1b5494
java/0189-rotate-array.java
@@ -0,0 +1,32 @@
1
+class Solution {
2
+ public void rotate(int[] nums, int k) {
3
+ //Do not return anything, modify nums in-place instead
4
+ k = k % nums.length;
5
+ int l = 0, r = nums.length - 1;
6
+ while(l < r) {
7
+ int tmp = nums[l];
8
+ nums[l] = nums[r];
9
+ nums[r] = tmp;
10
+ l += 1;
11
+ r -= 1;
12
+ }
13
+ l = 0;
14
+ r = k - 1;
15
16
17
18
19
20
21
22
+ l = k;
23
+ r = nums.length - 1;
24
25
26
27
28
29
30
31
32
+}
0 commit comments