mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
66 lines
2.2 KiB
HTML
66 lines
2.2 KiB
HTML
|
<p>You are given a string <code>s</code>.</p>
|
||
|
|
||
|
<p>A string <code>t</code> is called <strong>good</strong> if all characters of <code>t</code> occur the same number of times.</p>
|
||
|
|
||
|
<p>You can perform the following operations <strong>any number of times</strong>:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Delete a character from <code>s</code>.</li>
|
||
|
<li>Insert a character in <code>s</code>.</li>
|
||
|
<li>Change a character in <code>s</code> to its next letter in the alphabet.</li>
|
||
|
</ul>
|
||
|
|
||
|
<p><strong>Note</strong> that you cannot change <code>'z'</code> to <code>'a'</code> using the third operation.</p>
|
||
|
|
||
|
<p>Return<em> </em>the <strong>minimum</strong> number of operations required to make <code>s</code> <strong>good</strong>.</p>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong class="example">Example 1:</strong></p>
|
||
|
|
||
|
<div class="example-block">
|
||
|
<p><strong>Input:</strong> <span class="example-io">s = "acab"</span></p>
|
||
|
|
||
|
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||
|
|
||
|
<p><strong>Explanation:</strong></p>
|
||
|
|
||
|
<p>We can make <code>s</code> good by deleting one occurrence of character <code>'a'</code>.</p>
|
||
|
</div>
|
||
|
|
||
|
<p><strong class="example">Example 2:</strong></p>
|
||
|
|
||
|
<div class="example-block">
|
||
|
<p><strong>Input:</strong> <span class="example-io">s = "wddw"</span></p>
|
||
|
|
||
|
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||
|
|
||
|
<p><strong>Explanation:</strong></p>
|
||
|
|
||
|
<p>We do not need to perform any operations since <code>s</code> is initially good.</p>
|
||
|
</div>
|
||
|
|
||
|
<p><strong class="example">Example 3:</strong></p>
|
||
|
|
||
|
<div class="example-block">
|
||
|
<p><strong>Input:</strong> <span class="example-io">s = "aaabc"</span></p>
|
||
|
|
||
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||
|
|
||
|
<p><strong>Explanation:</strong></p>
|
||
|
|
||
|
<p>We can make <code>s</code> good by applying these operations:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Change one occurrence of <code>'a'</code> to <code>'b'</code></li>
|
||
|
<li>Insert one occurrence of <code>'c'</code> into <code>s</code></li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>Constraints:</strong></p>
|
||
|
|
||
|
<ul>
|
||
|
<li><code>3 <= s.length <= 2 * 10<sup>4</sup></code></li>
|
||
|
<li><code>s</code> contains only lowercase English letters.</li>
|
||
|
</ul>
|