Skip to content

Commit 93b348d

Browse files
authored
feat: add cs solution to lc problem: No.2785 (#1960)
1 parent 0b3fc2b commit 93b348d

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

solution/2700-2799/2785.Sort Vowels in a String/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ function sortVowels(s: string): string {
163163
}
164164
```
165165

166+
### **C#**
167+
168+
```cs
169+
public class Solution {
170+
public string SortVowels(string s) {
171+
List<char> vs = new List<char>();
172+
char[] cs = s.ToCharArray();
173+
foreach (char c in cs) {
174+
if (IsVowel(c)) {
175+
vs.Add(c);
176+
}
177+
}
178+
vs.Sort();
179+
for (int i = 0, j = 0; i < cs.Length; ++i) {
180+
if (IsVowel(cs[i])) {
181+
cs[i] = vs[j++];
182+
}
183+
}
184+
return new string(cs);
185+
}
186+
187+
public bool IsVowel(char c) {
188+
c = char.ToLower(c);
189+
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
190+
}
191+
}
192+
```
193+
166194
### **...**
167195

168196
```

solution/2700-2799/2785.Sort Vowels in a String/README_EN.md

+28
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,34 @@ function sortVowels(s: string): string {
153153
}
154154
```
155155

156+
### **C#**
157+
158+
```cs
159+
public class Solution {
160+
public string SortVowels(string s) {
161+
List<char> vs = new List<char>();
162+
char[] cs = s.ToCharArray();
163+
foreach (char c in cs) {
164+
if (IsVowel(c)) {
165+
vs.Add(c);
166+
}
167+
}
168+
vs.Sort();
169+
for (int i = 0, j = 0; i < cs.Length; ++i) {
170+
if (IsVowel(cs[i])) {
171+
cs[i] = vs[j++];
172+
}
173+
}
174+
return new string(cs);
175+
}
176+
177+
public bool IsVowel(char c) {
178+
c = char.ToLower(c);
179+
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
180+
}
181+
}
182+
```
183+
156184
### **...**
157185

158186
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Solution {
2+
public string SortVowels(string s) {
3+
List<char> vs = new List<char>();
4+
char[] cs = s.ToCharArray();
5+
foreach (char c in cs) {
6+
if (IsVowel(c)) {
7+
vs.Add(c);
8+
}
9+
}
10+
vs.Sort();
11+
for (int i = 0, j = 0; i < cs.Length; ++i) {
12+
if (IsVowel(cs[i])) {
13+
cs[i] = vs[j++];
14+
}
15+
}
16+
return new string(cs);
17+
}
18+
19+
public bool IsVowel(char c) {
20+
c = char.ToLower(c);
21+
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
22+
}
23+
}

0 commit comments

Comments
 (0)