forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_609.java
37 lines (34 loc) · 1.37 KB
/
_609.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class _609 {
public static class Solution1 {
public List<List<String>> findDuplicate(String[] paths) {
Map<String, List<String>> contentMap = new HashMap<>();
for (String path : paths) {
String[] contents = path.split(" ");
List<String> list = new ArrayList<>();
for (int i = 1; i < contents.length; i++) {
list.add(contents[i]);
int start = contents[i].indexOf('(');
int end = contents[i].indexOf(')');
String content = contents[i].substring(start + 1, end);
if (!contentMap.containsKey(content)) {
contentMap.put(content, new ArrayList<>());
}
List<String> dupFiles = contentMap.get(content);
dupFiles.add(contents[0] + "/" + contents[i].substring(0, start));
}
}
List<List<String>> result = new ArrayList<>();
for (String key : contentMap.keySet()) {
if (contentMap.get(key).size() > 1) {
result.add(contentMap.get(key));
}
}
return result;
}
}
}