Skip to content

Commit 4d3e43b

Browse files
committed
Sync LeetCode submission - Reverse Vowels of a String (rust)
1 parent fdb7abb commit 4d3e43b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
impl Solution {
2+
pub fn reverse_vowels(s: String) -> String {
3+
let mut vowels = Vec::new();
4+
for c in s.chars() {
5+
if is_vowel(&c) {
6+
vowels.push(c);
7+
}
8+
}
9+
10+
s.chars()
11+
.map(|x| {
12+
if is_vowel(&x) {
13+
vowels.pop().unwrap()
14+
} else {
15+
x
16+
}
17+
})
18+
.collect()
19+
}
20+
}
21+
22+
#[inline(always)]
23+
fn is_vowel(c: &char) -> bool {
24+
['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'].contains(c)
25+
}

0 commit comments

Comments
 (0)