From abf304dc1c9e2b3310d3c0597f4909bd5e62cd95 Mon Sep 17 00:00:00 2001 From: Manuel Pineda Date: Thu, 28 Jan 2021 19:50:21 +0100 Subject: [PATCH] Create 28.kt --- solved/LeetCode/Challenges/2020/January/28.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 solved/LeetCode/Challenges/2020/January/28.kt diff --git a/solved/LeetCode/Challenges/2020/January/28.kt b/solved/LeetCode/Challenges/2020/January/28.kt new file mode 100644 index 00000000..61980ff8 --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/28.kt @@ -0,0 +1,12 @@ +class Solution { + fun getSmallestString(n: Int, k: Int): String { + val ans = IntArray(n) {1} + var extra = k - n; + for (i in ans.indices.reversed()) { + val take = Math.min(extra, 25) + ans[i] += take + extra -= take + } + return ans.map {it -> (96 + it).toChar()}.joinToString(separator="") + } +}