1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-12 17:05:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (English)/转换字符串的最小操作次数(English) [minimum-operations-to-transform-string].html
2025-09-28 16:53:26 +08:00

53 lines
1.8 KiB
HTML

<p>You are given a string <code>s</code> consisting only of lowercase English letters.</p>
<p>You can perform the following operation any number of times (including zero):</p>
<ul>
<li>
<p>Choose any character <code>c</code> in the string and replace <strong>every</strong> occurrence of <code>c</code> with the <strong>next</strong> lowercase letter in the English alphabet.</p>
</li>
</ul>
<p>Return the <strong>minimum</strong> number of operations required to transform <code>s</code> into a string consisting of <strong>only</strong> <code>&#39;a&#39;</code> characters.</p>
<p><strong>Note: </strong>Consider the alphabet as circular, thus <code>&#39;a&#39;</code> comes after <code>&#39;z&#39;</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;yz&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>Change <code>&#39;y&#39;</code> to <code>&#39;z&#39;</code> to get <code>&quot;zz&quot;</code>.</li>
<li>Change <code>&#39;z&#39;</code> to <code>&#39;a&#39;</code> to get <code>&quot;aa&quot;</code>.</li>
<li>Thus, the answer is 2.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;a&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The string <code>&quot;a&quot;</code> only consists of <code>&#39;a&#39;</code> characters. Thus, the answer is 0.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>