- 哈希表
function groupAnagrams(strs: string[]): string[][] {
const map: Map<string, string[]> = new Map<string, string[]>();
for (const str of strs) {
const key: string = hash(str),
values: string[] = [...(map.get(key) || []), str];
map.set(key, values);
}
return [...map.values()];
};
function hash(str: string): string {
return [...str].sort().join('');
}