1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/具有给定数值的最小字符串 [smallest-string-with-a-given-numeric-value].html
2022-03-29 12:43:11 +08:00

38 lines
1.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p><strong>小写字符 </strong><strong>数值</strong> 是它在字母表中的位置(从 <code>1</code> 开始),因此 <code>a</code> 的数值为 <code>1</code> <code>b</code> 的数值为 <code>2</code> <code>c</code> 的数值为 <code>3</code> ,以此类推。</p>
<p>字符串由若干小写字符组成,<strong>字符串的数值</strong> 为各字符的数值之和。例如,字符串 <code>"abe"</code> 的数值等于 <code>1 + 2 + 5 = 8</code></p>
<p>给你两个整数 <code>n</code><code>k</code> 。返回 <strong>长度</strong> 等于 <code>n</code><strong>数值</strong> 等于 <code>k</code><strong>字典序最小</strong> 的字符串。</p>
<p>注意,如果字符串 <code>x</code> 在字典排序中位于 <code>y</code> 之前,就认为 <code>x</code> 字典序比 <code>y</code> 小,有以下两种情况:</p>
<ul>
<li><code>x</code><code>y</code> 的一个前缀;</li>
<li>如果 <code>i</code> 是 <code>x[i] != y[i]</code> 的第一个位置,且 <code>x[i]</code> 在字母表中的位置比 <code>y[i]</code> 靠前。</li>
</ul>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 3, k = 27
<strong>输出:</strong>"aay"
<strong>解释:</strong>字符串的数值为 1 + 1 + 25 = 27它是数值满足要求且长度等于 3 字典序最小的字符串。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 5, k = 73
<strong>输出:</strong>"aaszz"
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>n <= k <= 26 * n</code></li>
</ul>