Skip to content

Commit 2538757

Browse files
committed
Create 49.字母异位词分组.js
1 parent f3c0788 commit 2538757

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

49.字母异位词分组.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {string[]} strs
3+
* @return {string[][]}
4+
*/
5+
var groupAnagrams = function(strs) {
6+
const map = new Map();
7+
for (const str of strs) {
8+
const key = str.split('').sort().join('');
9+
if (map.has(key)) {
10+
map.get(key).push(str);
11+
} else {
12+
map.set(key, [str]);
13+
}
14+
}
15+
return Array.from(map.values());
16+
};

0 commit comments

Comments
 (0)