classSolution{ public List<List<String>> groupAnagrams(String[] strs) { List<List<String>> result = new ArrayList(); HashMap<String ,List<String>> map = new HashMap();
for ( String str: strs) { String key = count(str); List<String> list; if (!map.containsKey(key)) { list = new ArrayList<String>(); result.add(list); map.put(key,list);
}else { list = map.get(key); } list.add(str); } return result;
} public String count(String str){ int[] bit = newint[26]; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); bit[c -'a'] ++; } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < 26; i++) { char c = (char)('a' + i); for (int j = 0; j < bit[i]; j++) { stringBuilder.append(c); }