2785. Sort Vowels in a String Medium
1/**
2 * [2785] Sort Vowels in a String
3 *
4 * Given a 0-indexed string s, permute s to get a new string t such that:
5 *
6 * All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].
7 * The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].
8 *
9 * Return the resulting string.
10 * The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.
11 *
12 * <strong class="example">Example 1:
13 *
14 * Input: s = "lEetcOde"
15 * Output: "lEOtcede"
16 * Explanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.
17 *
18 * <strong class="example">Example 2:
19 *
20 * Input: s = "lYmpH"
21 * Output: "lYmpH"
22 * Explanation: There are no vowels in s (all characters in s are consonants), so we return "lYmpH".
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= s.length <= 10^5
28 * s consists only of letters of the English alphabet in uppercase and lowercase.
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/sort-vowels-in-a-string/
34// discuss: https://leetcode.com/problems/sort-vowels-in-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn sort_vowels(s: String) -> String {
40 String::new()
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_2785() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.