Skip to content

Commit 580bf13

Browse files
committed
feat: add ts solution to lc problem: No.0049
No.0049.Group Anagrams
1 parent 38fa2ec commit 580bf13

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

solution/0000-0099/0049.Group Anagrams/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ function groupAnagrams(strs: string[]): string[][] {
107107
}
108108
```
109109

110+
```ts
111+
function groupAnagrams(strs: string[]): string[][] {
112+
const map = new Map<string, string[]>();
113+
for (const str of strs) {
114+
const k = str.split('').sort().join('');
115+
map.set(k, (map.get(k) ?? []).concat([str]));
116+
}
117+
return [...map.values()];
118+
}
119+
```
120+
110121
### **C++**
111122

112123
```cpp

solution/0000-0099/0049.Group Anagrams/README_EN.md

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ function groupAnagrams(strs: string[]): string[][] {
7878
}
7979
```
8080

81+
```ts
82+
function groupAnagrams(strs: string[]): string[][] {
83+
const map = new Map<string, string[]>();
84+
for (const str of strs) {
85+
const k = str.split('').sort().join('');
86+
map.set(k, (map.get(k) ?? []).concat([str]));
87+
}
88+
return [...map.values()];
89+
}
90+
```
91+
8192
### **C++**
8293

8394
```cpp

0 commit comments

Comments
 (0)