https://leetcode.com/problems/find-duplicate-file-in-system/
public class Solution { public List<List<String>> findDuplicate(String[] paths) { List<List<String>> result = new ArrayList<>(); Map<String, List<String>> map = new HashMap<>(); for (String s : paths) { String[] tmp = s.split("[ ]"); for (int i = 1; i < tmp.length; i++) { String[] file = tmp[i].split("[ \\(\\)]"); if (!map.containsKey(file[1])) { map.put(file[1], new ArrayList<>()); } map.get(file[1]).add(tmp[0] + "/" + file[0]); } } for (Map.Entry<String, List<String>> entry: map.entrySet()) { if (entry.getValue().size() > 1) { result.add(new ArrayList<>(entry.getValue())); } } return result; } }

浙公网安备 33010602011771号