1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-12-21 03:13:45 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2025-12-17 09:38:38 +08:00
parent 19eb3b8380
commit 6dbedcccd7
40 changed files with 14240 additions and 9609 deletions

View File

@@ -0,0 +1,68 @@
<p>You are given a string <code>s</code> consisting of lowercase English words, each separated by a single space.</p>
<p>Determine how many vowels appear in the <strong>first</strong> word. Then, reverse each following word that has the <strong>same vowel count</strong>. Leave all remaining words unchanged.</p>
<p>Return the resulting string.</p>
<p>Vowels are <code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#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;cat and mice&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;cat dna mice&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The first word <code>&quot;cat&quot;</code> has 1 vowel.</li>
<li><code>&quot;and&quot;</code> has 1 vowel, so it is reversed to form <code>&quot;dna&quot;</code>.</li>
<li><code>&quot;mice&quot;</code> has 2 vowels, so it remains unchanged.</li>
<li>Thus, the resulting string is <code>&quot;cat dna mice&quot;</code>.</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;book is nice&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;book is ecin&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The first word <code>&quot;book&quot;</code> has 2 vowels.</li>
<li><code>&quot;is&quot;</code> has 1 vowel, so it remains unchanged.</li>
<li><code>&quot;nice&quot;</code> has 2 vowels, so it is reversed to form <code>&quot;ecin&quot;</code>.</li>
<li>Thus, the resulting string is <code>&quot;book is ecin&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;banana healthy&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;banana healthy&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>The first word <code>&quot;banana&quot;</code> has 3 vowels.</li>
<li><code>&quot;healthy&quot;</code> has 2 vowels, so it remains unchanged.</li>
<li>Thus, the resulting string is <code>&quot;banana healthy&quot;</code>.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code> consists of lowercase English letters and spaces.</li>
<li>Words in <code>s</code> are separated by a <strong>single</strong> space.</li>
<li><code>s</code> does <strong>not</strong> contain leading or trailing spaces.</li>
</ul>