dengxinyi 6 년 전
부모
커밋
438e3bf435
2개의 변경된 파일33개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      medium/609.find-duplicate-file-in-system.go
  2. 26 0
      medium/609.find-duplicate-file-in-system.java

+ 7 - 1
medium/609.find-duplicate-file-in-system.go

@@ -16,5 +16,11 @@ func findDuplicate(paths []string) [][]string {
 			}
 		}
 	}
-	return res
+	ans := make([][]string, 0)
+	for _, r := range res {
+		if 1 < len(r) {
+			ans = append(ans, r)
+		}
+	}
+	return ans
 }

+ 26 - 0
medium/609.find-duplicate-file-in-system.java

@@ -0,0 +1,26 @@
+class Solution {
+    public List<List<String>> findDuplicate(String[] paths) {
+        List<List<String>> res = new LinkedList<>();
+        HashMap<String, Integer> map = new HashMap<>();
+        for (String path : paths) {
+            String[] part = path.split(" ");
+            for (int i = 1; i < part.length; i++) {
+                String[] file = part[i].split("\\(");
+                Integer idx = map.get(file[1]);
+                if (idx == null) {
+                    res.add(new LinkedList<String>());
+                    idx = res.size() - 1;
+                    map.put(file[1], idx);
+                }
+                String fullPath = part[0] + "/" + file[0];
+                res.get(idx).add(fullPath);
+            }
+        }
+        Iterator<List<String>> iter = res.iterator();
+        while (iter.hasNext()) {
+            List<String> list = iter.next();
+            if (list.size() == 1) iter.remove();
+        }
+        return res;
+    }
+}