字母异位词分组 /* hashMap.computeIfAbsent(s, key -> new LinkedList<>()); hashmap中是否存在键s,不存在则创建键s,并添加值。 */ class Solution { public List<List<String>> groupAnagrams(String[] strs) { List<List<String>> res = new LinkedList<>(); LinkedHashMap<String, List<String>> hashMap = new LinkedHashMap<>(); for (int i = 0; i < strs.length; i++) { String str = strs[i]; char[] chars = str.toCharArray(); Arrays.sort(chars); String s = Arrays.toString(chars); hashMap.computeIfAbsent(s, key -> new LinkedList<>()); hashMap.get(s).add(str); } for (String s : hashMap.keySet()) { res.add(new LinkedList<>(hashMap.get(s))); } return res; } }