Skip to content

Commit 7824365

Browse files
committed
Create 2309-greatest-english-letter-in-upper-and-lower-case.rs
1 parent a1c2975 commit 7824365

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub fn greatest_letter(s: String) -> String {
2+
use std::collections::HashMap;
3+
let mut s_chars = s.chars().collect::<Vec<char>>();
4+
s_chars.sort_unstable();
5+
s_chars.dedup();
6+
let mut mmp = HashMap::new();
7+
let mut ret = '0';
8+
for c in s_chars {
9+
let cu = c.to_ascii_uppercase();
10+
let count = mmp.entry(cu).or_insert(0);
11+
*count += 1;
12+
if *count > 1 && cu > ret { ret = cu }
13+
}
14+
if ret == '0' { return String::new() }
15+
ret.to_string()
16+
}
17+
18+
fn main() {
19+
println!("{:?}", greatest_letter("AbCdEfGhIjK".to_string()));
20+
}

0 commit comments

Comments
 (0)