problems(kt): add “2264. Largest 3-Same-Digit Number in String”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
3b9f1bd2c0
commit
66b342212f
1 changed files with 14 additions and 0 deletions
14
problems/kt/largest-3-same-digit-number-in-string.kt
Normal file
14
problems/kt/largest-3-same-digit-number-in-string.kt
Normal 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()
|
||||
} ?: ""
|
||||
}
|
Loading…
Reference in a new issue