class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
Map<String, List<String>> map = new HashMap<>();
for (String str : strs) {
char[] cs = str.toCharArray();
Arrays.sort(cs);
String anagram = String.valueOf(cs);
if (!map.containsKey(anagram))
map.put(anagram, new ArrayList<String>());
map.get(anagram).add(str);
}
return new ArrayList(map.values());
}
}
groupAnagrams
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||