My LeetCode grinding. Trying to do a problem a day.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415
  1. class Solution:
  2. def groupAnagrams(self, strs):
  3. ana = dict()
  4. for s in strs:
  5. key = ''.join(sorted(s))
  6. if key in ana:
  7. ana[key].append(s)
  8. else:
  9. ana[key] = [s]
  10. return ana.values()
  11. s = Solution()
  12. print("Expected: [['ate', 'eat', 'tea'], ['nat', 'tan'], ['bat']]")
  13. print("Got:", s.groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))