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.
1 parent 8f7a907 commit e9eb1c4Copy full SHA for e9eb1c4
1 file changed
group-anagrams/jylee2033.py
@@ -0,0 +1,14 @@
1
+class Solution:
2
+ def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
3
+ anagram_map = {}
4
+ for word in strs:
5
+ key = "".join(sorted(word))
6
+ if key not in anagram_map:
7
+ anagram_map[key] = [word]
8
+ else:
9
+ anagram_map[key].append(word)
10
+
11
+ return list(anagram_map.values())
12
13
+# Time Complexity: O(N * K log K), N - number of strings, K - maximum length of a string (for sorting)
14
+# Space Complexity: O(N * K)
0 commit comments