{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "689d088dff924b3dba06a66fc6014101",
  "keywords": "哈希表,字符串,排序",
  "title": "字母异位词分组",
  "desc": [
    {
      "content": "\n<p>给定一个字符串数组，将字母异位词组合在一起。字母异位词指字母相同，但排列不同的字符串。</p>\n<p><strong>示例:</strong></p>\n<pre><strong>输入:</strong>[eat&quot;, &quot;tea&quot;, &quot;tan&quot;, &quot;ate&quot;, &quot;nat&quot;, &quot;bat&quot;]<strong><br />输出:</strong>[[ate&quot;,&quot;eat&quot;,&quot;tea&quot;],[&quot;nat&quot;,&quot;tan&quot;],[&quot;bat&quot;]]</pre>\n<p><strong>说明：</strong></p>\n<ul>\n<li>所有输入均为小写字母。</li>\n<li>不考虑答案输出的顺序。</li>\n</ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef groupAnagrams(self, strs):\n\t\tstrs.sort()\n\t\thash = {}\n\t\tfor s in strs:\n\t\t\tkey = self.hash_key(s)\n\t\t\ttry:\n\t\t\t\thash[key].append(s)\n\t\t\texcept KeyError:\n\t\t\t\thash[key] = [s]\n\t\treturn hash.values()\n\tdef hash_key(self, s):\n\t\ttable = [0] * 26\n\t\tfor ch in s:\n\t\t\tindex = ord(ch) - ord('a')\n\t\t\ttable[index] += 1\n\t\treturn str(table)\n# %%\ns = Solution()\nprint(s.groupAnagrams(strs = [\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"]))",
    "language": "python"
  },
  "node_id": "dailycode-9f59a4bafe424c768dc1883a7edfb04b",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470799"
}