File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public List <List <String >> findDuplicate (String [] paths ) {
3
+ HashMap <String , List <String >> hm = new HashMap <>();
4
+
5
+ for (int i =0 ; i <paths .length ; i ++) {
6
+ String full_path = paths [i ];
7
+ String [] split = full_path .split (" " );
8
+ String base_name = split [0 ];
9
+ for (int j =1 ; j <split .length ; j ++) {
10
+ String [] content = split [j ].split ("\\ (" );
11
+ String file_name = content [0 ];
12
+ String file_content = content [1 ];
13
+ String path = base_name + "/" + file_name ;
14
+ if (!hm .containsKey (file_content )) {
15
+ List <String > res = new ArrayList <>();
16
+ res .add (path );
17
+ hm .put (file_content , res );
18
+ } else {
19
+ List <String > getList = hm .get (file_content );
20
+ getList .add (path );
21
+ hm .put (file_content , getList );
22
+ }
23
+ }
24
+ }
25
+ List <List <String >> final_list = new ArrayList <>();
26
+
27
+ for (Map .Entry <String , List <String >> map : hm .entrySet ()) {
28
+ final_list .add (map .getValue ());
29
+ }
30
+ return final_list ;
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments