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.
2 parents e418651 + e6cf1b6 commit 0ebc31fCopy full SHA for 0ebc31f
Array/Rotate Array/Question.txt
@@ -0,0 +1 @@
1
+We have to rotate the elements of the given array k times to the right.
Array/Rotate Array/solution.kt
@@ -0,0 +1,23 @@
+internal class Solution {
2
+ fun rotate(nums:IntArray, k:Int) {
3
+ k = k % nums.size
4
+ val count = 0
5
+ val start = 0
6
+ while (count < nums.size)
7
+ {
8
+ val current = start
9
+ val prev = nums[start]
10
+ do
11
12
+ val next = (current + k) % nums.size
13
+ val temp = nums[next]
14
+ nums[next] = prev
15
+ prev = temp
16
+ current = next
17
+ count++
18
+ }
19
+ while (start != current)
20
+ start++
21
22
23
+}
0 commit comments