3775. Reverse Words With Same Vowel Count Medium

@problem@discussion
#Two Pointers#String#Simulation



1/**
2 * [3775] Reverse Words With Same Vowel Count
3 *
4 * You are given a string s consisting of lowercase English words, each separated by a single space.
5 * Determine how many vowels appear in the first word. Then, reverse each following word that has the same vowel count. Leave all remaining words unchanged.
6 * Return the resulting string.
7 * Vowels are 'a', 'e', 'i', 'o', and 'u'.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">s = "cat and mice"</span>
12 * Output: <span class="example-io">"cat dna mice"</span>
13 * Explanation:​​​​​​​
14 * 
15 * 	The first word "cat" has 1 vowel.
16 * 	"and" has 1 vowel, so it is reversed to form "dna".
17 * 	"mice" has 2 vowels, so it remains unchanged.
18 * 	Thus, the resulting string is "cat dna mice".
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">s = "book is nice"</span>
23 * Output: <span class="example-io">"book is ecin"</span>
24 * Explanation:
25 * 
26 * 	The first word "book" has 2 vowels.
27 * 	"is" has 1 vowel, so it remains unchanged.
28 * 	"nice" has 2 vowels, so it is reversed to form "ecin".
29 * 	Thus, the resulting string is "book is ecin".
30 * </div>
31 * <strong class="example">Example 3:
32 * <div class="example-block">
33 * Input: <span class="example-io">s = "banana healthy"</span>
34 * Output: <span class="example-io">"banana healthy"</span>
35 * Explanation:
36 * 
37 * 	The first word "banana" has 3 vowels.
38 * 	"healthy" has 2 vowels, so it remains unchanged.
39 * 	Thus, the resulting string is "banana healthy".
40 * </div>
41 *  
42 * Constraints:
43 * 
44 * 	1 <= s.length <= 10^5
45 * 	s consists of lowercase English letters and spaces.
46 * 	Words in s are separated by a single space.
47 * 	s does not contain leading or trailing spaces.
48 * 
49 */
50pub struct Solution {}
51
52// problem: https://leetcode.com/problems/reverse-words-with-same-vowel-count/
53// discuss: https://leetcode.com/problems/reverse-words-with-same-vowel-count/discuss/?currentPage=1&orderBy=most_votes&query=
54
55// submission codes start here
56
57impl Solution {
58    pub fn reverse_words(s: String) -> String {
59        String::new()
60    }
61}
62
63// submission codes end
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68
69    #[test]
70    fn test_3775() {
71    }
72}
73

Back
© 2026 bowen.ge All Rights Reserved.