代码1
Runtime: 6 ms
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
Map<String, List<String>> map = new HashMap();
for (String s : strs){
char[] chars = s.toCharArray();
Arrays.sort(chars);
String string = new String(chars);
map.putIfAbsent(string, new ArrayList());
map.get(string).add(s);
}
return new ArrayList(map.values());
}
}