Skip to content

Commit 7963135

Browse files
committed
group anagrams solution
1 parent 7fd29f2 commit 7963135

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

group-anagrams/yuseok89.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# TC: O(N * LlogL)
2+
# SC: O(N * L)
3+
class Solution:
4+
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
5+
6+
ans = defaultdict(list)
7+
8+
for s in strs:
9+
ans[''.join(sorted(s))].append(s)
10+
11+
return list(ans.values())
12+

0 commit comments

Comments
 (0)