{"id":2929,"date":"2020-02-12T16:00:48","date_gmt":"2020-02-12T08:00:48","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2929"},"modified":"2020-02-12T16:00:48","modified_gmt":"2020-02-12T08:00:48","slug":"%e3%80%90leetcode%e3%80%910049-%e5%ad%97%e6%af%8d%e5%bc%82%e4%bd%8d%e8%af%8d%e5%88%86%e7%bb%84","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2929\/","title":{"rendered":"\u3010LeetCode\u30110049 \u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/group-anagrams\/\">https:\/\/leetcode-cn.com\/problems\/group-anagrams\/<\/a><\/p>\n\n\n<p><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def groupAnagrams(self, strs):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> strs: List[str]\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: List[List[str]]\n        \"\"\"\n        <\/em>if len(strs) == 1:\n            return [strs]\n        temp_strs = strs[:]\n        for i in range(len(strs)):\n            strs[i] = \"\".join((lambda x: (x.sort(), x)[1])(list(strs[i])))\n        # \u4fdd\u5b58\u7ed3\u679c\n        res_strs = []\n        # \u4fdd\u5b58\u5df2\u7ecf\u6709\u4e86\u7684\u6392\u5e8f\u540e\u7684\u5b57\u7b26\u4e32\n        temp_list = []\n        for i in range(len(strs)):\n            if strs[i] in temp_list:\n                idx = temp_list.index(strs[i])\n                res_strs[idx].append(temp_strs[i])\n            else:\n                res_strs.append([temp_strs[i]])\n                temp_list.append(strs[i])\n        return res_strs\nif __name__ == '__main__':\n    strs = [\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]\n    print(Solution().groupAnagrams(strs))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<em>\n<\/em>class Solution(object):\n    def groupAnagrams(self, strs):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> strs: List[str]\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: List[List[str]]\n        \"\"\"\n        <\/em>if len(strs) == 1:\n            return [strs]\n        temp_strs = strs[:]\n        for i in range(len(strs)):\n            strs[i] = \"\".join((lambda x: (x.sort(), x)[1])(list(strs[i])))\n        # \u4fdd\u5b58\u7ed3\u679c\n        res_strs = []\n        # \u4fdd\u5b58\u5df2\u7ecf\u6709\u4e86\u7684\u6392\u5e8f\u540e\u7684\u5b57\u7b26\u4e32\n        temp_list = []\n        for i in range(len(strs)):\n            if strs[i] in temp_list:\n                idx = temp_list.index(strs[i])\n                res_strs[idx].append(temp_strs[i])\n            else:\n                res_strs.append([temp_strs[i]])\n                temp_list.append(strs[i])\n        return res_strs\nif __name__ == '__main__':\n    strs = [\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]\n    print(Solution().groupAnagrams(strs))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u9996\u5148\u5bf9\u6240\u6709\u7684\u5b57\u7b26\u4e32\u8fdb\u884cascii\u7801\u6392\u5e8f\uff1b\u7136\u540e\u6839\u636e\u6392\u5e8f\u7ed3\u679c\uff0c\u5982\u679c\u7ed3\u679c\u4e00\u6837\u8bf4\u660e\u662f\u5f02\u4f4d\u8bcd\uff0c\u6839\u636e\u6392\u5e8f\u7ed3\u679c\u653e\u8fdb\u4e0d\u540c\u7684\u5217\u8868\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/group-anagrams\/ # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":1601,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2929"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2929"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2929\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2929"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}