LeetCode/kt/clear-digits.kt
2025-02-10 08:54:23 +01:00

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 = "")
}