Medium
用char[]排序后的新string做key来建立hashMap. 最后把每个key的所有value加到List里的list就行
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
List<List<String>> res = new ArrayList<>();
Map<String, List<String>> map = new HashMap<>();
for (String str : strs){
char[] chas = str.toCharArray();
Arrays.sort(chas);
String chars = String.valueOf(chas);
if (!map.containsKey(chars)){
map.put(chars, new ArrayList<String>());
}
map.get(chars).add(str);
}
for (String key : map.keySet()){
Collections.sort(map.get(key));
res.add(map.get(key));
}
return res;
}
}