# 字母异位词分组

<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>

## template

```java

import java.util.*;

public class GroupAnagrams {

	public List<List<String>> groupAnagrams(String[] strs) {
		HashMap<String, ArrayList<String>> map = new HashMap<>();
		for (String str : strs) {
			char[] cs = str.toCharArray();
			Arrays.sort(cs);

			String key = String.valueOf(cs);
			if (!map.containsKey(key)) {
				map.put(key, new ArrayList<>());
			}
			map.get(key).add(str);
		}
		return new ArrayList(map.values());
	}

	public List<List<String>> groupAnagrams2(String[] strs) {
		if (strs.length <= 0) {
			return new ArrayList<>();
		}
		HashMap<String, ArrayList<String>> map = new HashMap<>();
		for (String str : strs) {
			char[] cs = str.toCharArray();
			int[] count = new int[26];
			for (char c : cs) {
				++count[c - 'a'];
			}
			StringBuilder s = new StringBuilder("");
			for (int num : count) {
				s.append(num);
			}

			String key = String.valueOf(s);

			if (!map.containsKey(key)) {
				map.put(key, new ArrayList<>());
			}
			map.get(key).add(str);
		}
		return new ArrayList(map.values());
	}
}

```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```