File tree 3 files changed +79
-0
lines changed
solution/2700-2799/2785.Sort Vowels in a String
3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,34 @@ function sortVowels(s: string): string {
163
163
}
164
164
```
165
165
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
+
166
194
### ** ...**
167
195
168
196
```
Original file line number Diff line number Diff line change @@ -153,6 +153,34 @@ function sortVowels(s: string): string {
153
153
}
154
154
```
155
155
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
+
156
184
### ** ...**
157
185
158
186
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments