valid-anagram

This commit is contained in:
Gleb Koval 2022-06-02 23:45:04 +01:00
parent 0a8bf37562
commit 6a5f3eccaf
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 17 additions and 0 deletions

17
valid-anagram/sol.rs Normal file
View File

@ -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)
}
}