Skip to content

Commit 9baac3a

Browse files
committed
49
1 parent 68e10cf commit 9baac3a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

group-anagrams/jeldo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)