LeetCode/problems/kt/largest-3-same-digit-number-in-string.kt
2023-12-04 12:08:47 +01:00

14 lines
331 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()
} ?: ""
}