g0301_0400.s0344_reverse_string.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g0301_0400.s0344_reverse_string
// #Easy #Top_Interview_Questions #String #Two_Pointers #Recursion #Algorithm_I_Day_4_Two_Pointers
// #Udemy_Strings #2022_11_18_Time_445_ms_(69.75%)_Space_61.9_MB_(33.77%)
class Solution {
fun reverseString(s: CharArray) {
var left = 0
var right = s.size - 1
while (left < right) {
val tmp = s[left]
s[left++] = s[right]
s[right--] = tmp
}
}
}