![JAR search and dependency download from the Maven repository](/logo.png)
g2601_2700.s2697_lexicographically_smallest_palindrome.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 g2601_2700.s2697_lexicographically_smallest_palindrome
// #Easy #String #Two_Pointers #2023_07_29_Time_267_ms_(100.00%)_Space_37.7_MB_(77.78%)
class Solution {
fun makeSmallestPalindrome(s: String): String {
var l = 0
var r = s.lastIndex
val res = s.toCharArray()
while (l <= r) {
if (s[l] < s[r])
res[r] = s[l]
else
res[l] = s[r]
l++
r--
}
return String(res)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy