Skip to content

Commit 007f326

Browse files
committed
group-anagrams 풀이 추가
1 parent af8473f commit 007f326

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

group-anagrams/junzero741.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// TC: O(N*KlogK)
2+
// SC: O(N*K)
3+
function groupAnagrams(strs: string[]): string[][] {
4+
5+
const idMap = new Map<string, string[]>();
6+
7+
for(const str of strs) {
8+
const id = str.split("").sort().join("");
9+
10+
if(!idMap.has(id)) {
11+
idMap.set(id, [])
12+
}
13+
14+
idMap.get(id)!.push(str)
15+
}
16+
17+
return [...idMap.values()]
18+
19+
};

0 commit comments

Comments
 (0)