We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3544142 commit d65d5d9Copy full SHA for d65d5d9
kotlin/0344-reverse-string.kt
@@ -0,0 +1,30 @@
1
+/*
2
+* Using 2 variables for the pointers
3
+*/
4
+class Solution {
5
+ fun reverseString(s: CharArray): Unit {
6
+ var low = 0
7
+ var high = s.size-1
8
+ while(low < high){
9
+ val temp = s[high]
10
+ s[high] = s[low]
11
+ s[low] = temp
12
+ low++
13
+ high--
14
+ }
15
16
+}
17
+
18
19
+* Using one variable for the pointers
20
21
22
23
+ val size = s.size
24
+ for(i in 0 until size/2){
25
+ val temp = s[i]
26
+ s[i] = s[size-1-i]
27
+ s[size-1-i] = temp
28
29
30
0 commit comments