File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 20
20
36|[ Valid Sudoku] ( ./0036-valid-sudoku.js ) |Medium|
21
21
41|[ First Missing Positive] ( ./0041-first-missing-positive.js ) |Hard|
22
22
43|[ Multiply Strings] ( ./0043-multiply-strings.js ) |Medium|
23
+ 49|[ Group Anagrams] ( ./0049-group-anagrams.js ) |Medium|
23
24
50|[ Pow(x, n)] ( ./0050-powx-n.js ) |Medium|
24
25
54|[ Spiral Matrix] ( ./0054-spiral-matrix.js ) |Medium|
25
26
58|[ Length of Last Word] ( ./0058-length-of-last-word.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 49. Group Anagrams
3
+ * https://leetcode.com/problems/group-anagrams/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an array of strings `strs`, group the anagrams together. You can return the
7
+ * answer in any order.
8
+ *
9
+ * An Anagram is a word or phrase formed by rearranging the letters of a different
10
+ * word or phrase, typically using all the original letters exactly once.
11
+ */
12
+
13
+ /**
14
+ * @param {string[] } strs
15
+ * @return {string[][] }
16
+ */
17
+ var groupAnagrams = function ( strs ) {
18
+ const map = { } ;
19
+
20
+ strs . forEach ( str => {
21
+ const key = [ ...str ] . sort ( ) ;
22
+ map [ key ] = map [ key ] ? [ ...map [ key ] , str ] : [ str ] ;
23
+ } ) ;
24
+
25
+ return Object . values ( map ) ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments