人生苦短,我用python

在leetcode上看了一段python代码,亲身感觉到 “人生苦短,我用python”。

49. Group Anagrams

class Solution(object):
    def groupAnagrams(self, strs):
        ans = collections.defaultdict(list)
        for s in strs:
            ans[tuple(sorted(s))].append(s)
        return ans.values()

Leave a Reply

Your email address will not be published. Required fields are marked *