Skip to content

Commit 80fde46

Browse files
authored
Merge pull request #1759 from DaleSeo/main
[DaleSeo] WEEK 02 solutions
2 parents 8dd6cc3 + 4391284 commit 80fde46

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)