We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 720b898 + 72ac8bb commit 8a4a45dCopy full SHA for 8a4a45d
1 file changed
group-anagrams/DaleSeo.rs
@@ -0,0 +1,17 @@
1
+// TC: O(n * k) where n = number of strings, k = max string length
2
+// SC: O(n * k)
3
+use std::collections::HashMap;
4
+
5
+impl Solution {
6
+ pub fn group_anagrams(strs: Vec<String>) -> Vec<Vec<String>> {
7
+ let mut anagrams: HashMap<[u8; 26], Vec<String>> = HashMap::new();
8
+ for s in strs {
9
+ let mut count = [0u8; 26];
10
+ for b in s.bytes() {
11
+ count[(b - b'a') as usize] += 1;
12
+ }
13
+ anagrams.entry(count).or_default().push(s);
14
15
+ anagrams.into_values().collect()
16
17
+}
0 commit comments