Skip to content

Commit 4391284

Browse files
committed
valid-anagram
1 parent 32d80da commit 4391284

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

valid-anagram/DaleSeo.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::collections::HashMap;
2+
3+
// TC: O(n)
4+
// SC: O(n)
5+
impl Solution {
6+
pub fn is_anagram(s: String, t: String) -> bool {
7+
let mut counter: HashMap<char, usize> = HashMap::new();
8+
9+
for ch in s.chars() {
10+
*counter.entry(ch).or_insert(0) += 1;
11+
}
12+
13+
for ch in t.chars() {
14+
*counter.entry(ch).or_insert(0) -= 1;
15+
}
16+
17+
return counter.values().all(|cnt| *cnt == 0)
18+
}
19+
}

0 commit comments

Comments
 (0)