{"id":2252,"date":"2022-01-22T10:49:13","date_gmt":"2022-01-22T02:49:13","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2252"},"modified":"2022-01-22T10:49:14","modified_gmt":"2022-01-22T02:49:14","slug":"leetcodeday49","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/22\/leetcodeday49\/","title":{"rendered":"leetcodeday49 &#8211;\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u8bf7\u4f60\u5c06&nbsp;<strong>\u5b57\u6bcd\u5f02\u4f4d\u8bcd<\/strong>&nbsp;\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u5217\u8868\u3002<\/p>\n\n\n\n<p><strong>\u5b57\u6bcd\u5f02\u4f4d\u8bcd<\/strong>&nbsp;\u662f\u7531\u91cd\u65b0\u6392\u5217\u6e90\u5355\u8bcd\u7684\u5b57\u6bcd\u5f97\u5230\u7684\u4e00\u4e2a\u65b0\u5355\u8bcd\uff0c\u6240\u6709\u6e90\u5355\u8bcd\u4e2d\u7684\u5b57\u6bcd\u901a\u5e38\u6070\u597d\u53ea\u7528\u4e00\u6b21\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong> strs = &#91;\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]\n<strong>\u8f93\u51fa: <\/strong>&#91;&#91;\"bat\"],&#91;\"nat\",\"tan\"],&#91;\"ate\",\"eat\",\"tea\"]]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong> strs = &#91;\"\"]\n<strong>\u8f93\u51fa: <\/strong>&#91;&#91;\"\"]]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong> strs = &#91;\"a\"]\n<strong>\u8f93\u51fa: <\/strong>&#91;&#91;\"a\"]]<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>1 &lt;= strs.length &lt;= 10<sup>4<\/sup><\/code><\/li><li><code>0 &lt;= strs[i].length &lt;= 100<\/code><\/li><li><code>strs[i]<\/code>&nbsp;\u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd<\/li><\/ul>\n\n\n\n<p>\u66b4\u529b\u7834\u4e07\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=49 lang=python3\r\n#\r\n# &#91;49] \u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def groupAnagrams(self, strs: List&#91;str]) -> List&#91;List&#91;str]]:\r\n        def matchstr(s,p):\r\n            lens=len(s)\r\n            lenp=len(p)\r\n            if lens==lenp:\r\n                for i in  range(len(p)):\r\n                    if p&#91;i] in s:\r\n                        h=s.index(p&#91;i])\r\n                        s=s&#91;0:h]+s&#91;h+1:]\r\n                        continue\r\n                    else:\r\n                        return False\r\n                return True\r\n            else:return False\r\n        rev=list()\r\n        rev.append(&#91;strs&#91;0]])\r\n        for i in range(1,len(strs)):\r\n            k=0\r\n            for j in range(len(rev)):\r\n                #print(rev,j,i)\r\n                if matchstr(rev&#91;j]&#91;0],strs&#91;i]):\r\n                    rev&#91;j].append(strs&#91;i])\r\n                    k=1\r\n                    break\r\n            if k==0:\r\n                rev.append(&#91;strs&#91;i]])\r\n        return rev<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-263.png\" alt=\"\" class=\"wp-image-2253\" width=\"600\" height=\"175\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-263.png 727w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-263-300x88.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u8bf7\u4f60\u5c06&nbsp;\u5b57\u6bcd\u5f02\u4f4d\u8bcd&nbsp;\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u53ef\u4ee5\u6309\u4efb\u610f\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u5217\u8868\u3002 \u5b57\u6bcd\u5f02\u4f4d &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/22\/leetcodeday49\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday49 &#8211;\u5b57\u6bcd\u5f02\u4f4d\u8bcd\u5206\u7ec4<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2252"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2252"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2252\/revisions"}],"predecessor-version":[{"id":2255,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2252\/revisions\/2255"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2252"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}