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:
parent
fb06fb1fc6
commit
e147651e12
1 changed files with 13 additions and 0 deletions
13
kt/valid-palindrome.kt
Normal file
13
kt/valid-palindrome.kt
Normal 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] }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue