Files
CodeTest/leetcode/valid-anagram/solution_1409125750.rs

23 lines
580 B
Rust

use std::collections::HashMap;
impl Solution {
pub fn count(s: String) -> HashMap<char, usize>{
s.chars().fold(HashMap::with_capacity(s.len()), |mut map, c| {
match map.get_mut(&c) {
Some(n) => {
*n += 1;
},
None => {
map.insert(c, 1);
}
}
map
})
}
pub fn is_anagram(s: String, t: String) -> bool {
let scount = Self::count(s);
let tcount = Self::count(t);
scount == tcount
}
}