1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-16 16:36:56 +02:00
LeetCode/kt/largest-3-same-digit-number-in-string.kt
Matej Focko aaaebf1d52
style(kt): reformat the files
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-05-17 18:23:38 +02:00

15 lines
383 B
Kotlin

class Solution {
fun largestGoodInteger(num: String): String =
num
.asSequence()
.windowed(3)
.filter { s ->
s[0] == s[1] && s[1] == s[2]
}
.map { window ->
window.joinToString("")
}
.maxByOrNull { num ->
num.toInt()
} ?: ""
}