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 68e10cf commit 9baac3aCopy full SHA for 9baac3a
group-anagrams/jeldo.py
@@ -0,0 +1,10 @@
1
+from collections import defaultdict
2
+
3
4
+class Solution:
5
+ # O(n*mlogm), n = len(str), m = the length of the longest string
6
+ def groupAnagrams(self, strs: list[str]) -> list[list[str]]:
7
+ group = defaultdict(list)
8
+ for s in strs:
9
+ group[''.join(sorted(s))].append(s)
10
+ return list(group.values())
0 commit comments