valid-anagram
This commit is contained in:
parent
0a8bf37562
commit
6a5f3eccaf
|
@ -0,0 +1,17 @@
|
|||
// For unicode hashmaps may be used
|
||||
impl Solution {
|
||||
pub fn is_anagram(s: String, t: String) -> bool {
|
||||
let mut s_map = s.bytes()
|
||||
.fold([0; 26], |mut map, chr| {
|
||||
map[chr as usize - 97] += 1;
|
||||
map
|
||||
});
|
||||
t.bytes()
|
||||
.fold(s_map, |mut map, chr| {
|
||||
map[chr as usize - 97] -= 1;
|
||||
map
|
||||
})
|
||||
.iter()
|
||||
.all(|&count| count == 0)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue