URL: https://leetcode.com/problems/clear-digits/ Signed-off-by: Matej Focko <me@mfocko.xyz>
11 lines
290 B
Kotlin
11 lines
290 B
Kotlin
class Solution {
|
|
fun clearDigits(s: String): String =
|
|
s.fold(mutableListOf<Char>()) { chars, c ->
|
|
when {
|
|
c.isDigit() -> chars.removeLast()
|
|
else -> chars.add(c)
|
|
}
|
|
|
|
chars
|
|
}.joinToString(separator = "")
|
|
}
|