-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
32 lines (29 loc) · 746 Bytes
/
Solution.cs
File metadata and controls
32 lines (29 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Solution
{
public string SortVowels(string s)
{
List<char> vowels = [];
int n = s.Length;
char[] str = s.ToCharArray();
for (int i = 0; i < n; i++)
{
if (IsVowels(s[i]))
{
vowels.Add(s[i]);
str[i] = '#';
}
}
vowels.Sort();
for (int i = 0, j = 0; i < n && j < vowels.Count; i++)
{
if (str[i] == '#')
{
str[i] = vowels[j++];
}
}
return new(str);
}
bool IsVowels(char c)
=> c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'
|| c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
}