File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed
solution/2700-2799/2785.Sort Vowels in a String Expand file tree Collapse file tree 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 {
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```
Original file line number Diff line number Diff 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 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