class Solution { public List> findDuplicate(String[] paths) { List> res = new LinkedList<>(); HashMap 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()); idx = res.size() - 1; map.put(file[1], idx); } String fullPath = part[0] + "/" + file[0]; res.get(idx).add(fullPath); } } Iterator> iter = res.iterator(); while (iter.hasNext()) { List list = iter.next(); if (list.size() == 1) iter.remove(); } return res; } }