1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
pub struct Solution;
#[allow(unused)]
impl Solution {
pub fn first_uniq_char(s: String) -> char {
let mut map = std::collections::HashMap::new();
for c in s.chars() {
*map.entry(c).or_insert(0) += 1;
}
for c in s.chars() {
if map[&c] == 1 {
return c
}
}
' '
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test() {
assert_eq!(Solution::first_uniq_char("leetcode".to_string()), 'l');
assert_eq!(Solution::first_uniq_char("loveleetcode".to_string()), 'v');
}
}