Skip to content

Commit 8f4354b

Browse files
authored
feat: add solutions to lc problem: No.3541 (#4717)
1 parent 2543cf3 commit 8f4354b

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

solution/3500-3599/3541.Find Most Frequent Vowel and Consonant/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,31 @@ func maxFreqSum(s string) int {
169169
}
170170
```
171171

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+
172197
#### TypeScript
173198

174199
```ts
@@ -190,6 +215,29 @@ function maxFreqSum(s: string): number {
190215
}
191216
```
192217

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+
193241
<!-- tabs:end -->
194242

195243
<!-- solution:end -->

solution/3500-3599/3541.Find Most Frequent Vowel and Consonant/README_EN.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,54 @@ function maxFreqSum(s: string): number {
196196
}
197197
```
198198

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+
199247
<!-- tabs:end -->
200248

201249
<!-- solution:end -->
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

0 commit comments

Comments
 (0)