Skip to content

Commit 0332db0

Browse files
committed
https://leetcode.cn/problems/find-duplicate-file-in-system/
1 parent bc8840a commit 0332db0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/find-duplicate-file-in-system/
14+
1315
https://leetcode.cn/problems/design-in-memory-file-system/
1416

1517
https://leetcode.cn/problems/all-possible-full-binary-trees/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default function findDuplicate(paths: string[]): string[][] {
2+
const map = new Map<string, string[]>();
3+
4+
for (const ps of paths) {
5+
const [directory, ...contents] = ps.split(" ");
6+
7+
for (const con of contents) {
8+
const [name, content] = con.split(/\(|\)/g).filter(Boolean);
9+
10+
const arr = map.get(content) ?? [];
11+
arr.push(directory + "/" + name);
12+
map.set(content, arr);
13+
}
14+
}
15+
16+
return [...map.values()].filter((a) => a.length > 1);
17+
}

0 commit comments

Comments
 (0)