Files
leetcode/src/exercises/49.group-anagrams.js
2025-07-14 10:09:13 -04:00

19 lines
394 B
JavaScript

// @leet start
/**
* @param {string[]} strs
* @return {string[][]}
*/
var groupAnagrams = function(strs) {
if (strs.length < 2) return [strs];
const map = {};
for (const str of strs) {
const key = str.split("").sort().join("");
if (!map[key]) {
map[key] = [];
}
map[key].push(str);
}
return Object.values(map);
};
// @leet end