Middle-题目83：49. Group Anagrams

Given an array of strings, group anagrams together.

For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],
Return:

[
["ate", "eat","tea"],
["nat","tan"],
["bat"]
]

public class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
Map<String, List<String>> map = new HashMap<String, List<String>>();
for(String str : strs) {
char[] carr = str.toCharArray();  // 将单词按字母排序
Arrays.sort(carr);
String key = new String(carr);
List<String> list = map.get(key);
if(list == null) {
list = new ArrayList<String>();
}
map.put(key, list);
}
List<List<String>> res = new ArrayList<List<String>>();
for(String key : map.keySet()) {
List<String> curr = map.get(key);
Collections.sort(curr); // 将列表按单词排序
}
return res;
}
}

26ms,beats 73.2%,众数33ms,8.78%
Cmershen的碎碎念：

leetcode 49. Group Anagrams （Java实现）

2017-01-06 15:47:40

LeetCode-49. Group Anagrams (JAVA)按照字典序分组

2017-04-21 13:08:27

LeetCode-49-Group Anagrams(哈希)-Medium

2016-01-10 18:32:32

LeetCode（49）Group Anagrams

2015-09-01 20:28:44

[leetcode] 49. Group Anagrams 解题报告

2016-02-29 05:02:32

LeetCode 49. Group Anagrams （Python）

2017-08-05 19:28:54

leetcode：Group Anagrams 【Java】

2016-03-11 14:51:12

[python]leetcode(49). Group Anagrams

2017-09-27 22:38:34

49. Group Anagrams(Python3)

2018-01-26 21:23:53

[LeetCode] Group Anagrams

2015-08-19 11:07:03