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)/最多 K 次交换相邻数位后得到的最小整数 [minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits].html
2022-03-29 12:43:11 +08:00

58 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>给你一个字符串&nbsp;<code>num</code> 和一个整数&nbsp;<code>k</code> 。其中,<code>num</code> 表示一个很大的整数,字符串中的每个字符依次对应整数上的各个 <strong>数位</strong></p>
<p>你可以交换这个整数相邻数位的数字 <strong>最多</strong>&nbsp;<code>k</code>&nbsp;次。</p>
<p>请你返回你能得到的最小整数,并以字符串形式返回。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/06/17/q4_1.jpg" style="height:40px; width:500px" /></p>
<pre>
<strong>输入:</strong>num = &quot;4321&quot;, k = 4
<strong>输出:</strong>&quot;1342&quot;
<strong>解释:</strong>4321 通过 4 次交换相邻数位得到最小整数的步骤如上图所示。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>num = &quot;100&quot;, k = 1
<strong>输出:</strong>&quot;010&quot;
<strong>解释:</strong>输出可以包含前导 0 ,但输入保证不会有前导 0 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>num = &quot;36789&quot;, k = 1000
<strong>输出:</strong>&quot;36789&quot;
<strong>解释:</strong>不需要做任何交换。
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>num = &quot;22&quot;, k = 22
<strong>输出:</strong>&quot;22&quot;
</pre>
<p><strong>示例 5</strong></p>
<pre>
<strong>输入:</strong>num = &quot;9438957234785635408&quot;, k = 23
<strong>输出:</strong>&quot;0345989723478563548&quot;
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= num.length &lt;= 30000</code></li>
<li><code>num</code>&nbsp;只包含&nbsp;<strong>数字</strong>&nbsp;且不含有<strong>&nbsp;前导 0&nbsp;</strong></li>
<li><code>1 &lt;= k &lt;= 10^9</code></li>
</ul>