Skip to content

Commit 52f5171

Browse files
committed
feat: add 0236 Group Anagrams solution
1 parent e6658bb commit 52f5171

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

group-anagrams/hyogshin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from collections import defaultdict
2+
from typing import List
3+
class Solution:
4+
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
5+
groups = defaultdict(list)
6+
for s in strs:
7+
cnt = [0] * 26
8+
for ch in s:
9+
cnt[ord(ch) - ord('a')] += 1
10+
groups[tuple(cnt)].append(s)
11+
return list(groups.values())
12+
13+
if __name__ == "__main__":
14+
sol = Solution()
15+
print(sol.groupAnagrams(["eat","tea","tan","ate","nat","bat"]))

0 commit comments

Comments
 (0)