File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 2727| 34| [ 在排序数组中查找元素的第一个和最后一个位置] ( https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/ ) | [ JavaScript] ( ./algorithms/find-first-and-last-position-of-element-in-sorted-array.js ) | Medium|
2828| 35| [ 搜索插入位置] ( https://leetcode.cn/problems/search-insert-position/ ) | [ JavaScript] ( ./algorithms/search-insert-position.js ) | Easy|
2929| 48| [ 旋转图像] ( https://leetcode.cn/problems/rotate-image/ ) | [ JavaScript] ( ./algorithms/rotate-image.js ) | Medium|
30+ | 49| [ 字母异位词分组] ( https://leetcode.cn/problems/group-anagrams/ ) | [ JavaScript] ( ./algorithms/group-anagrams.js ) | Medium|
3031| 58| [ 最后一个单词的长度] ( https://leetcode.cn/problems/length-of-last-word/ ) | [ JavaScript] ( ./algorithms/length-of-last-word.js ) | Easy|
3132| 53| [ 最大子数组和] ( https://leetcode.cn/problems/maximum-subarray/ ) | [ JavaScript] ( ./algorithms/maximum-subarray.js ) | Easy|
3233| 66| [ 加一] ( https://leetcode-cn.com/problems/plus-one/ ) | [ JavaScript] ( ./algorithms/plus-one.js ) | Easy|
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string[] } strs
3+ * @return {string[][] }
4+ */
5+ var groupAnagrams = function ( strs ) {
6+ const map = new Map ( ) ;
7+
8+ for ( let word of strs ) {
9+ let temp = word . split ( "" ) . sort ( ) . join ( "" ) ;
10+
11+ if ( map . has ( temp ) ) {
12+ map . get ( temp ) . push ( word ) ;
13+ } else {
14+ map . set ( temp , [ word ] ) ;
15+ }
16+ }
17+
18+ return Array . from ( map . values ( ) ) ;
19+ } ;
You can’t perform that action at this time.
0 commit comments