# 字母异位词分组

<p>给定一个字符串数组，将字母异位词组合在一起。字母异位词指字母相同，但排列不同的字符串。</p>
<p><strong>示例:</strong></p>
<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>
<p><strong>说明：</strong></p>
<ul>
    <li>所有输入均为小写字母。</li>
    <li>不考虑答案输出的顺序。</li>
</ul>

以下程序实现了这一功能，请你填补空白处内容：

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	vector<vector<string>> groupAnagrams(vector<string> &strs)
	{
		vector<vector<string>> res;
		unordered_map<string, vector<string>> ht;
		for (const auto &str : strs)
		{
			int counts[26] = {0};
			for (char c : str)
			{
				counts[c - 'a']++;
			}
			string key;
			for (int i : counts)
			{
				________________;
			}
			ht[key].push_back(str);
		}
		for (const auto &t : ht)
		{
			res.push_back(t.second);
		}
		return res;
	}
};
```

## template

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	vector<vector<string>> groupAnagrams(vector<string> &strs)
	{
		vector<vector<string>> res;
		unordered_map<string, vector<string>> ht;
		for (const auto &str : strs)
		{
			int counts[26] = {0};
			for (char c : str)
			{
				counts[c - 'a']++;
			}
			string key;
			for (int i : counts)
			{
				key.push_back('#');
				key.push_back(i + '0');
			}
			ht[key].push_back(str);
		}
		for (const auto &t : ht)
		{
			res.push_back(t.second);
		}
		return res;
	}
};
```

## 答案

```cpp
key.push_back('#');
key.push_back(i + '0');
```

## 选项

### A

```cpp
key.push_back('#');
key.push_back('0');
```

### B

```cpp
key.push_back(i + '#');
key.push_back(i + '0');
```

### C

```cpp
key.push_back(i + '#');
key.push_back('0');
```