diff --git a/valid-anagram/DaleSeo.rs b/valid-anagram/DaleSeo.rs new file mode 100644 index 000000000..027b82671 --- /dev/null +++ b/valid-anagram/DaleSeo.rs @@ -0,0 +1,19 @@ +use std::collections::HashMap; + +// TC: O(n) +// SC: O(n) +impl Solution { + pub fn is_anagram(s: String, t: String) -> bool { + let mut counter: HashMap = HashMap::new(); + + for ch in s.chars() { + *counter.entry(ch).or_insert(0) += 1; + } + + for ch in t.chars() { + *counter.entry(ch).or_insert(0) -= 1; + } + + return counter.values().all(|cnt| *cnt == 0) + } +}