Created
April 5, 2026 06:00
-
-
Save ksamirdev/ddc827b9dc5f3b66a5733d33e67bb40c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import defaultdict | |
| class Solution: | |
| def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | |
| anagrams = defaultdict(list) | |
| for st in strs: | |
| count = [0] * 26 | |
| for c in st: | |
| count[ord(c) - ord('a')] += 1 | |
| key = tuple(count) | |
| anagrams[key].append(st) | |
| return list(anagrams.values()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment