mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-12 17:05:15 +08:00
update
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<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>'a'</code> characters.</p>
|
||||
|
||||
<p><strong>Note: </strong>Consider the alphabet as circular, thus <code>'a'</code> comes after <code>'z'</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "yz"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Change <code>'y'</code> to <code>'z'</code> to get <code>"zz"</code>.</li>
|
||||
<li>Change <code>'z'</code> to <code>'a'</code> to get <code>"aa"</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 = "a"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The string <code>"a"</code> only consists of <code>'a'</code> characters. Thus, the answer is 0.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 5 * 10<sup>5</sup></code></li>
|
||||
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||
</ul>
|
Reference in New Issue
Block a user