Skip to content

Commit a1406ef

Browse files
authored
Create 609. Find Duplicate File in System
1 parent af32925 commit a1406ef

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

609. Find Duplicate File in System

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public List<List<String>> findDuplicate(String[] paths) {
3+
Map<String,List<String>> store = new HashMap<>();
4+
5+
for(String path:paths){
6+
String[] arr = path.split(" ");
7+
String directory = arr[0];
8+
9+
for(int i=1;i<arr.length;i++){
10+
//fileName(content)
11+
String fileName = arr[i].substring(0,arr[i].indexOf("("));
12+
String content = arr[i].substring(arr[i].indexOf("(")+1,arr[i].length()-1);
13+
List<String> filepaths = store.getOrDefault(content,new ArrayList<>());
14+
filepaths.add(directory +"/"+fileName);
15+
store.put(content,filepaths);
16+
}
17+
}
18+
19+
store.entrySet().removeIf(entry -> entry.getValue().size()<2);
20+
21+
return new ArrayList<>(store.values());
22+
}
23+
}

0 commit comments

Comments
 (0)