
题目字母异位词分组描述给你一个字符串数组请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。示例输入: strs [eat, tea, tan, ate, nat, bat] 输出: [[bat],[nat,tan],[ate,eat,tea]] 解释 在 strs 中没有字符串可以通过重新排列来形成 bat。 字符串 nat 和 tan 是字母异位词因为它们可以重新排列以形成彼此。 字符串 ate eat 和 tea 是字母异位词因为它们可以重新排列以形成彼此。算法思路将每个字符串重新排序然后判断是否有相同的即为异位词通过 HashMap 存储Key 存储重新排序后的字符串Value 存储一个 List 集合里面包含全部的 Key 的异位词最后获取HashMap中存储的全部集合。**getOrDefault()**为获取 key 的 value如果不存在则执行后面的操作。class GroupAnagrams{ public ListListString groupAnagrams(String[] strs){ HashMapString,ListString hashMap new HashMap(); for (String s : strs) { char[] array s.toCharArray(); Arrays.sort(array); String key new String(array); ListString list hashMap.getOrDefault(key, new ArrayListString()); list.add(key); hashMap.put(key,list); } return new ArrayList(hashMap.values()); } }注只为记录自己的练习过程方便回顾