File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,9 @@ https://neetcode.io/roadmap
4
4
5
5
### Leetcode
6
6
7
- <!-- create a table for me -->
8
-
9
7
| # | Title | Difficulty | Solution |
10
8
| --- | ----------------------------------------------------------------------- | ---------- | ---------------------------------------------------- |
11
9
| 217 | [ Contains Duplicate] ( https://leetcode.com/problems/contains-duplicate/ ) | Easy | [ TypeScript] ( ./TypeScript/217.contains-duplicate.ts ) |
12
10
| 242 | [ Valid Anagram] ( https://leetcode.com/problems/valid-anagram/ ) | Easy | [ TypeScript] ( ./TypeScript/242.valid-anagram.ts ) |
13
11
| 242 | [ Two Sum] ( https://leetcode.com/problems/two-sum/ ) | Easy | [ TypeScript] ( ./TypeScript/1.two-sum.ts ) |
12
+ | 49 | [ Group Anagrams] ( https://leetcode.com/problems/two-sum/ ) | Medium | [ TypeScript] ( ./TypeScript/49.group-anagrams.ts ) |
Original file line number Diff line number Diff line change
1
+ function groupAnagrams ( strs : string [ ] ) : string [ ] [ ] {
2
+ const map = new Map < string , string [ ] > ( ) ;
3
+
4
+ strs . forEach ( ( s ) => {
5
+ const identity = new Array ( 26 ) . fill ( 0 ) ; // it also can be the sorted string
6
+
7
+ for ( let i = 0 ; i < s . length ; i ++ ) {
8
+ identity [ s . charCodeAt ( i ) - 97 ] += 1 ;
9
+ }
10
+
11
+ const key = identity . join ( "," ) ;
12
+ const anagrams = map . get ( key ) ?? [ ] ;
13
+
14
+ anagrams . push ( s ) ;
15
+ map . set ( key , anagrams ) ;
16
+ } ) ;
17
+
18
+ return Array . from ( map . values ( ) ) ;
19
+ }
You can’t perform that action at this time.
0 commit comments