Skip to content

Commit

Permalink
49
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeldo committed Jan 7, 2025
1 parent 68e10cf commit 9baac3a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions group-anagrams/jeldo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from collections import defaultdict


class Solution:
# O(n*mlogm), n = len(str), m = the length of the longest string
def groupAnagrams(self, strs: list[str]) -> list[list[str]]:
group = defaultdict(list)
for s in strs:
group[''.join(sorted(s))].append(s)
return list(group.values())

0 comments on commit 9baac3a

Please sign in to comment.