| @@ -0,0 +1,15 @@ | |||
| class Solution: | |||
| def groupAnagrams(self, strs): | |||
| ana = dict() | |||
| for s in strs: | |||
| key = ''.join(sorted(s)) | |||
| if key in ana: | |||
| ana[key].append(s) | |||
| else: | |||
| ana[key] = [s] | |||
| return ana.values() | |||
| s = Solution() | |||
| print("Expected: [['ate', 'eat', 'tea'], ['nat', 'tan'], ['bat']]") | |||
| print("Got:", s.groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"])) | |||
| @@ -0,0 +1,17 @@ | |||
| Given an array of strings, group anagrams together. | |||
| Example: | |||
| Input: ["eat", "tea", "tan", "ate", "nat", "bat"], | |||
| Output: | |||
| [ | |||
| ["ate","eat","tea"], | |||
| ["nat","tan"], | |||
| ["bat"] | |||
| ] | |||
| Note: | |||
| All inputs will be in lowercase. | |||
| The order of your output does not matter. | |||
| @@ -0,0 +1,3 @@ | |||
| #!/bin/bash | |||
| python3 main.py | |||