mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
32 lines
1.8 KiB
HTML
32 lines
1.8 KiB
HTML
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and so on.</p>
|
|
|
|
<p>The <strong>numeric value</strong> of a <strong>string</strong> consisting of lowercase characters is defined as the sum of its characters' numeric values. For example, the numeric value of the string <code>"abe"</code> is equal to <code>1 + 2 + 5 = 8</code>.</p>
|
|
|
|
<p>You are given two integers <code>n</code> and <code>k</code>. Return <em>the <strong>lexicographically smallest string</strong> with <strong>length</strong> equal to <code>n</code> and <strong>numeric value</strong> equal to <code>k</code>.</em></p>
|
|
|
|
<p>Note that a string <code>x</code> is lexicographically smaller than string <code>y</code> if <code>x</code> comes before <code>y</code> in dictionary order, that is, either <code>x</code> is a prefix of <code>y</code>, or if <code>i</code> is the first position such that <code>x[i] != y[i]</code>, then <code>x[i]</code> comes before <code>y[i]</code> in alphabetic order.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> n = 3, k = 27
|
|
<strong>Output:</strong> "aay"
|
|
<strong>Explanation:</strong> The numeric value of the string is 1 + 1 + 25 = 27, and it is the smallest string with such a value and length equal to 3.
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> n = 5, k = 73
|
|
<strong>Output:</strong> "aaszz"
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
|
<li><code>n <= k <= 26 * n</code></li>
|
|
</ul>
|