public List<List<String>> groupAnagrams(String[] strs) {
List<List<String>> res = new ArrayList<>();
if (strs != null) {
Map<Integer, List<String>> kvs = new HashMap<>();
for (String s : strs) {
int key = getKey(s);
if (kvs.get(key) != null) {
kvs.get(key).add(s);
} else {
List<String> value = new ArrayList<>();
value.add(s);
kvs.put(key, value);
}
}
if (kvs != null) {
for (Integer integer : kvs.keySet()) {
res.add(kvs.get(integer));
}
}
}
return res;
}
public int getKey(String s) {
int[] nums = new int[26];
for (int i = 0; i < s.length(); i++) {
nums[s.charAt(i) - 'a']++;
}
return Arrays.hashCode(nums);
}