给定一个字符串数组,将字母异位词组合在一起。字母异位词指字母相同,但排列不同的字符串。
输入: ["eat", "tea", "tan", "ate", "nat", "bat"]输出:[["ate","eat","tea"],["nat","tan"],["bat"]]
/*** 哈希表 + 排序* 时间复杂度:O(n*k log k)* 空间复杂度:O(n*k)*/var groupAnagrams = function (strs) {const map = {}for (const str of strs) {const key = str.split('').sort().join('')if (map[key]) {map[key].push(str)} else {map[key] = [str]}}return Object.keys(map).map((key) => map[key])}
