|
| 1 | +<h2><a href="https://leetcode.com/problems/reverse-words-with-same-vowel-count">3775. Reverse Words With Same Vowel Count</a></h2><h3>Medium</h3><hr><p>You are given a string <code>s</code> consisting of lowercase English words, each separated by a single space.</p> |
| 2 | + |
| 3 | +<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> |
| 4 | + |
| 5 | +<p>Return the resulting string.</p> |
| 6 | + |
| 7 | +<p>Vowels are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<div class="example-block"> |
| 13 | +<p><strong>Input:</strong> <span class="example-io">s = "cat and mice"</span></p> |
| 14 | + |
| 15 | +<p><strong>Output:</strong> <span class="example-io">"cat dna mice"</span></p> |
| 16 | + |
| 17 | +<p><strong>Explanation:</strong></p> |
| 18 | + |
| 19 | +<ul> |
| 20 | +<li>The first word <code>"cat"</code> has 1 vowel.</li> |
| 21 | +<li><code>"and"</code> has 1 vowel, so it is reversed to form <code>"dna"</code>.</li> |
| 22 | +<li><code>"mice"</code> has 2 vowels, so it remains unchanged.</li> |
| 23 | +<li>Thus, the resulting string is <code>"cat dna mice"</code>.</li> |
| 24 | +</ul> |
| 25 | +</div> |
| 26 | + |
| 27 | +<p><strong class="example">Example 2:</strong></p> |
| 28 | + |
| 29 | +<div class="example-block"> |
| 30 | +<p><strong>Input:</strong> <span class="example-io">s = "book is nice"</span></p> |
| 31 | + |
| 32 | +<p><strong>Output:</strong> <span class="example-io">"book is ecin"</span></p> |
| 33 | + |
| 34 | +<p><strong>Explanation:</strong></p> |
| 35 | + |
| 36 | +<ul> |
| 37 | +<li>The first word <code>"book"</code> has 2 vowels.</li> |
| 38 | +<li><code>"is"</code> has 1 vowel, so it remains unchanged.</li> |
| 39 | +<li><code>"nice"</code> has 2 vowels, so it is reversed to form <code>"ecin"</code>.</li> |
| 40 | +<li>Thus, the resulting string is <code>"book is ecin"</code>.</li> |
| 41 | +</ul> |
| 42 | +</div> |
| 43 | + |
| 44 | +<p><strong class="example">Example 3:</strong></p> |
| 45 | + |
| 46 | +<div class="example-block"> |
| 47 | +<p><strong>Input:</strong> <span class="example-io">s = "banana healthy"</span></p> |
| 48 | + |
| 49 | +<p><strong>Output:</strong> <span class="example-io">"banana healthy"</span></p> |
| 50 | + |
| 51 | +<p><strong>Explanation:</strong></p> |
| 52 | + |
| 53 | +<ul> |
| 54 | +<li>The first word <code>"banana"</code> has 3 vowels.</li> |
| 55 | +<li><code>"healthy"</code> has 2 vowels, so it remains unchanged.</li> |
| 56 | +<li>Thus, the resulting string is <code>"banana healthy"</code>.</li> |
| 57 | +</ul> |
| 58 | +</div> |
| 59 | + |
| 60 | +<p> </p> |
| 61 | +<p><strong>Constraints:</strong></p> |
| 62 | + |
| 63 | +<ul> |
| 64 | +<li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 65 | +<li><code>s</code> consists of lowercase English letters and spaces.</li> |
| 66 | +<li>Words in <code>s</code> are separated by a <strong>single</strong> space.</li> |
| 67 | +<li><code>s</code> does <strong>not</strong> contain leading or trailing spaces.</li> |
| 68 | +</ul> |
0 commit comments