Skip to content

Commit 85204c8

Browse files
committed
duplicate files in directory
1 parent f9551cd commit 85204c8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Strings/findDuplicate.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)