kt: refactor «3272. Find the Count of Good Integers»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-04-12 11:41:24 +02:00
parent 3b04cd9900
commit 2fa0295ff1
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -22,17 +22,17 @@ class Solution {
val base = (1..(n - 1) / 2).fold(1) { acc, _ -> acc * 10 } val base = (1..(n - 1) / 2).fold(1) { acc, _ -> acc * 10 }
val skip = n.and(1) val skip = n.and(1)
for (i in base..10 * base - 1) { (base..10 * base - 1)
var s = i.toString() .map { i ->
s += StringBuilder(s).reverse().substring(skip) var s = i.toString()
s += StringBuilder(s).reverse().substring(skip)
val palindrome = s.toLong() s to s.toLong()
if (palindrome % k == 0L) { }.filter { (_, it) -> it % k == 0L }
val chars = s.toCharArray() .forEach { (it, _) ->
val chars = it.toCharArray()
chars.sort() chars.sort()
add(String(chars)) add(String(chars))
} }
}
} }
fun countGoodIntegers( fun countGoodIntegers(