kt: refactor «3272. Find the Count of Good Integers»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
3b04cd9900
commit
2fa0295ff1
1 changed files with 8 additions and 8 deletions
|
@ -22,17 +22,17 @@ class Solution {
|
|||
val base = (1..(n - 1) / 2).fold(1) { acc, _ -> acc * 10 }
|
||||
val skip = n.and(1)
|
||||
|
||||
for (i in base..10 * base - 1) {
|
||||
var s = i.toString()
|
||||
s += StringBuilder(s).reverse().substring(skip)
|
||||
|
||||
val palindrome = s.toLong()
|
||||
if (palindrome % k == 0L) {
|
||||
val chars = s.toCharArray()
|
||||
(base..10 * base - 1)
|
||||
.map { i ->
|
||||
var s = i.toString()
|
||||
s += StringBuilder(s).reverse().substring(skip)
|
||||
s to s.toLong()
|
||||
}.filter { (_, it) -> it % k == 0L }
|
||||
.forEach { (it, _) ->
|
||||
val chars = it.toCharArray()
|
||||
chars.sort()
|
||||
add(String(chars))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun countGoodIntegers(
|
||||
|
|
Loading…
Add table
Reference in a new issue