1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00

problems(kt): add “2264. Largest 3-Same-Digit Number in String”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-12-04 12:08:47 +01:00
parent 3b9f1bd2c0
commit 66b342212f
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,14 @@
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()
} ?: ""
}