From 35e2f493aea13c83fabcc91cf7c74e9d214c4807 Mon Sep 17 00:00:00 2001 From: isaiahliu Date: Tue, 14 Jan 2025 15:15:07 +0800 Subject: [PATCH] 1 --- src/main/kotlin/p32xx/Problem3270.kt | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/p32xx/Problem3270.kt b/src/main/kotlin/p32xx/Problem3270.kt index 63c0d1e1..44430dd2 100644 --- a/src/main/kotlin/p32xx/Problem3270.kt +++ b/src/main/kotlin/p32xx/Problem3270.kt @@ -1,20 +1,29 @@ package p32xx import util.expect +import java.util.* fun main() { class Solution { fun generateKey(num1: Int, num2: Int, num3: Int): Int { - var nums = intArrayOf(num1, num2, num3) - var b = 1 - var result = 0 + val nums = LinkedList() + nums += num1 + nums += num2 + nums += num3 + var result = 0 + var b = 1 repeat(4) { - result += b * nums.minOf { - (it % 10).also { - it / 10 - } + var min = 10 + repeat(3) { + val num = nums.poll() + + min = minOf(min, num % 10) + + nums += num / 10 } + + result += min * b b *= 10 }