File tree Expand file tree Collapse file tree 4 files changed +134
-0
lines changed
solution/3500-3599/3541.Find Most Frequent Vowel and Consonant Expand file tree Collapse file tree 4 files changed +134
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,31 @@ func maxFreqSum(s string) int {
169
169
}
170
170
```
171
171
172
+ #### Rust
173
+
174
+ ``` rust
175
+ use std :: collections :: HashMap ;
176
+
177
+ impl Solution {
178
+ pub fn max_freq_sum (s : String ) -> i32 {
179
+ let mut cnt : HashMap <char , i32 > = HashMap :: new ();
180
+ for c in s . chars () {
181
+ * cnt . entry (c ). or_insert (0 ) += 1 ;
182
+ }
183
+ let mut a = 0 ;
184
+ let mut b = 0 ;
185
+ for (c , v ) in cnt {
186
+ if " aeiou" . contains (c ) {
187
+ a = a . max (v );
188
+ } else {
189
+ b = b . max (v );
190
+ }
191
+ }
192
+ a + b
193
+ }
194
+ }
195
+ ```
196
+
172
197
#### TypeScript
173
198
174
199
``` ts
@@ -190,6 +215,29 @@ function maxFreqSum(s: string): number {
190
215
}
191
216
```
192
217
218
+ #### C#
219
+
220
+ ``` cs
221
+ public class Solution {
222
+ public int MaxFreqSum (string s ) {
223
+ int [] cnt = new int [26 ];
224
+ foreach (char c in s ) {
225
+ cnt [c - 'a' ]++ ;
226
+ }
227
+ int a = 0 , b = 0 ;
228
+ for (int i = 0 ; i < 26 ; i ++ ) {
229
+ char c = (char )('a' + i );
230
+ if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) {
231
+ a = Math .Max (a , cnt [i ]);
232
+ } else {
233
+ b = Math .Max (b , cnt [i ]);
234
+ }
235
+ }
236
+ return a + b ;
237
+ }
238
+ }
239
+ ```
240
+
193
241
<!-- tabs: end -->
194
242
195
243
<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -196,6 +196,54 @@ function maxFreqSum(s: string): number {
196
196
}
197
197
```
198
198
199
+ #### Rust
200
+
201
+ ``` rust
202
+ use std :: collections :: HashMap ;
203
+
204
+ impl Solution {
205
+ pub fn max_freq_sum (s : String ) -> i32 {
206
+ let mut cnt : HashMap <char , i32 > = HashMap :: new ();
207
+ for c in s . chars () {
208
+ * cnt . entry (c ). or_insert (0 ) += 1 ;
209
+ }
210
+ let mut a = 0 ;
211
+ let mut b = 0 ;
212
+ for (c , v ) in cnt {
213
+ if " aeiou" . contains (c ) {
214
+ a = a . max (v );
215
+ } else {
216
+ b = b . max (v );
217
+ }
218
+ }
219
+ a + b
220
+ }
221
+ }
222
+ ```
223
+
224
+ #### C#
225
+
226
+ ``` cs
227
+ public class Solution {
228
+ public int MaxFreqSum (string s ) {
229
+ int [] cnt = new int [26 ];
230
+ foreach (char c in s ) {
231
+ cnt [c - 'a' ]++ ;
232
+ }
233
+ int a = 0 , b = 0 ;
234
+ for (int i = 0 ; i < 26 ; i ++ ) {
235
+ char c = (char )('a' + i );
236
+ if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) {
237
+ a = Math .Max (a , cnt [i ]);
238
+ } else {
239
+ b = Math .Max (b , cnt [i ]);
240
+ }
241
+ }
242
+ return a + b ;
243
+ }
244
+ }
245
+ ```
246
+
199
247
<!-- tabs: end -->
200
248
201
249
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ public int MaxFreqSum ( string s ) {
3
+ int [ ] cnt = new int [ 26 ] ;
4
+ foreach ( char c in s ) {
5
+ cnt [ c - 'a' ] ++ ;
6
+ }
7
+ int a = 0 , b = 0 ;
8
+ for ( int i = 0 ; i < 26 ; i ++ ) {
9
+ char c = ( char ) ( 'a' + i ) ;
10
+ if ( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) {
11
+ a = Math . Max ( a , cnt [ i ] ) ;
12
+ } else {
13
+ b = Math . Max ( b , cnt [ i ] ) ;
14
+ }
15
+ }
16
+ return a + b ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ use std:: collections:: HashMap ;
2
+
3
+ impl Solution {
4
+ pub fn max_freq_sum ( s : String ) -> i32 {
5
+ let mut cnt: HashMap < char , i32 > = HashMap :: new ( ) ;
6
+ for c in s. chars ( ) {
7
+ * cnt. entry ( c) . or_insert ( 0 ) += 1 ;
8
+ }
9
+ let mut a = 0 ;
10
+ let mut b = 0 ;
11
+ for ( c, v) in cnt {
12
+ if "aeiou" . contains ( c) {
13
+ a = a. max ( v) ;
14
+ } else {
15
+ b = b. max ( v) ;
16
+ }
17
+ }
18
+ a + b
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments