1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-27 10:40:26 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/使字符频率相等的最少操作次数 [minimum-operations-to-make-character-frequencies-equal].html

68 lines
2.1 KiB
HTML
Raw Normal View History

2024-12-20 00:35:26 +08:00
<p>给你一个字符串&nbsp;<code>s</code>&nbsp;</p>
<p>如果字符串 <code>t</code>&nbsp;中的字符出现次数相等,那么我们称&nbsp;<code>t</code>&nbsp;<strong>好的</strong>&nbsp;</p>
<p>你可以执行以下操作 <strong>任意次</strong>&nbsp;</p>
<ul>
<li>&nbsp;<code>s</code>&nbsp;中删除一个字符。</li>
<li>&nbsp;<code>s</code>&nbsp;中添加一个字符。</li>
<li>&nbsp;<code>s</code>&nbsp;中一个字母变成字母表中下一个字母。</li>
</ul>
<p><b>注意</b>&nbsp;,第三个操作不能将&nbsp;<code>'z'</code>&nbsp;变为&nbsp;<code>'a'</code>&nbsp;</p>
<p>请你返回将 <code>s</code>&nbsp;<strong></strong>&nbsp;<strong>最少</strong>&nbsp;操作次数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "acab"</span></p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><b>解释:</b></p>
<p>删掉一个字符&nbsp;<code>'a'</code>&nbsp;<code>s</code>&nbsp;变为好的。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "wddw"</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p><code>s</code>&nbsp;一开始就是好的,所以不需要执行任何操作。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "aaabc"</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p>通过以下操作,将&nbsp;<code>s</code>&nbsp;变好:</p>
<ul>
<li>将一个&nbsp;<code>'a'</code>&nbsp;变为&nbsp;<code>'b'</code>&nbsp;</li>
<li><code>s</code>&nbsp;中插入一个&nbsp;<code>'c'</code>&nbsp;</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 2&nbsp;* 10<sup>4</sup></code></li>
<li><code>s</code>&nbsp;只包含小写英文字母。</li>
</ul>