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 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(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue