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; } }