From 439128463bd473472a5e7624a46f22177f715325 Mon Sep 17 00:00:00 2001 From: Dale Seo Date: Thu, 31 Jul 2025 19:55:53 -0400 Subject: [PATCH] valid-anagram --- valid-anagram/DaleSeo.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 valid-anagram/DaleSeo.rs 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) + } +}