kt: add «125. Valid Palindrome»

URL:	https://leetcode.com/problems/valid-palindrome/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-03-05 22:35:34 +01:00
parent fb06fb1fc6
commit e147651e12
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

13
kt/valid-palindrome.kt Normal file
View file

@ -0,0 +1,13 @@
class Solution {
fun isPalindrome(s: String): Boolean =
s.toCharArray()
.map { c -> c.toLowerCase() }
.filter { c -> c.isLetterOrDigit() }
.toCharArray()
.let { s ->
s.indices
.map { l -> l to s.size - l - 1 }
.takeWhile { (l, r) -> l < r }
.all { (l, r) -> s[l] == s[r] }
}
}