Public class Num49 groupAnagrams(String[] STRS) {public List<List<String>> groupAnagrams(String[] STRS) { Value as required collection HashMap<String, List<String>> map = new HashMap<>();for (String str : strs) {
char[] arr = str.toCharArray();
Arrays.sort(arr);
String key = String.valueOf(arr);
if(! map.containsKey(key)) { map.put(key, new ArrayList<>()); } map.get(key).add(str); }returnnew ArrayList<>(map.values()); }}Copy the code