Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions solution/2700-2799/2785.Sort Vowels in a String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,33 @@ function sortVowels(s: string): string {
}
```

#### Rust

```rust
impl Solution {
pub fn sort_vowels(s: String) -> String {
fn is_vowel(c: char) -> bool {
matches!(c.to_ascii_lowercase(), 'a' | 'e' | 'i' | 'o' | 'u')
}

let mut vs: Vec<char> = s.chars().filter(|&c| is_vowel(c)).collect();
vs.sort_unstable();

let mut cs: Vec<char> = s.chars().collect();
let mut j = 0;

for (i, c) in cs.clone().into_iter().enumerate() {
if is_vowel(c) {
cs[i] = vs[j];
j += 1;
}
}

cs.into_iter().collect()
}
}
```

#### C#

```cs
Expand Down
27 changes: 27 additions & 0 deletions solution/2700-2799/2785.Sort Vowels in a String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ function sortVowels(s: string): string {
}
```

#### Rust

```rust
impl Solution {
pub fn sort_vowels(s: String) -> String {
fn is_vowel(c: char) -> bool {
matches!(c.to_ascii_lowercase(), 'a' | 'e' | 'i' | 'o' | 'u')
}

let mut vs: Vec<char> = s.chars().filter(|&c| is_vowel(c)).collect();
vs.sort_unstable();

let mut cs: Vec<char> = s.chars().collect();
let mut j = 0;

for (i, c) in cs.clone().into_iter().enumerate() {
if is_vowel(c) {
cs[i] = vs[j];
j += 1;
}
}

cs.into_iter().collect()
}
}
```

#### C#

```cs
Expand Down
22 changes: 22 additions & 0 deletions solution/2700-2799/2785.Sort Vowels in a String/Solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
impl Solution {
pub fn sort_vowels(s: String) -> String {
fn is_vowel(c: char) -> bool {
matches!(c.to_ascii_lowercase(), 'a' | 'e' | 'i' | 'o' | 'u')
}

let mut vs: Vec<char> = s.chars().filter(|&c| is_vowel(c)).collect();
vs.sort_unstable();

let mut cs: Vec<char> = s.chars().collect();
let mut j = 0;

for (i, c) in cs.clone().into_iter().enumerate() {
if is_vowel(c) {
cs[i] = vs[j];
j += 1;
}
}

cs.into_iter().collect()
}
}