File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
find-duplicate-file-in-system Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ leetcode 测试
10
10
11
11
##### 包含的内容如下
12
12
13
+ https://leetcode.cn/problems/find-duplicate-file-in-system/
14
+
13
15
https://leetcode.cn/problems/design-in-memory-file-system/
14
16
15
17
https://leetcode.cn/problems/all-possible-full-binary-trees/
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments