diff --git a/valid-anagram/sol.rs b/valid-anagram/sol.rs new file mode 100644 index 0000000..01fe551 --- /dev/null +++ b/valid-anagram/sol.rs @@ -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) + } +} \ No newline at end of file