Clean Java
please see @Ericxxt \'s answer in the comment, lc has added more testcases and below answer cannot pass.\n\nwe have 4 steps to do this task\n\n1. add all the pa
please see @Ericxxt \'s answer in the comment, lc has added more testcases and below answer cannot pass.\n\nwe have 4 steps to do this task\n\n1. add all the path to Trie (if you are not familiar with this, please refer to https://leetcode.com/problems/implement-trie-prefix-tree/)\n2. we generate hashkey for each Trie Node, hashKey is all children name this node has, we just comcatenate all its children\'s name together\n3. we use hashmap to see if anyNode hashKey appear more than once, remove it from the Trie\n4. convert back Trie to individual path list, this use normal backtracking\n\n```\nclass Solution {\n    Trie root = new Trie();\n    Map<String, Integer> map = new HashMap<>();\n    List<List<String>> res = new ArrayList<>();\n    \n    public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {\n\n        //add to Trie\n        addToTrie(root, paths);\n\n        //add hashKey use suffix\n        generateHash(root);\n        \n        //remove duplicate path\n        remove(root);\n        \n        //convert back\n        convertBack(root, new ArrayList<>());\n        \n        return res;\n    }\n    \n    private void addToTrie(Trie root, List<List<String>> paths) {\n        for (List<String> path : paths) {\n            Trie cur = root;\n            for (String s : path) {\n                if (!cur.children.containsKey(s)) cur.children.put(s, new Trie(s));\n                cur = cur.children.get(s);\n            }\n        }\n    }\n    \n    private void convertBack(Trie cur, List<String> level) {\n        if (level.size() != 0) res.add(new ArrayList<>(level));\n        for (String childName : cur.children.keySet()) {\n            level.add(childName);\n            Trie child = cur.children.get(childName);\n            convertBack(child, level);\n            level.remove(level.size() - 1);\n        }\n    }\n    \n    private void remove(Trie cur) {\n        if (cur.children.size() == 0) return;\n        List<String> toDelete = new ArrayList<>();\n        for (String childName : cur.children.keySet()) {\n            Trie child = cur.children.get(childName);\n            remove(child);\n            if (map.containsKey(child.key) && map.get(child.key) > 1) toDelete.add(childName);\n        }\n        for (String s : toDelete) cur.children.remove(s);\n    }\n    \n    private String generateHash(Trie cur) {\n        StringBuilder sb = new StringBuilder();\n        if (cur.children.size() == 0) return sb.toString();\n        for (String childName : cur.children.keySet()) {\n            Trie child = cur.children.get(childName);\n            generateHash(child);\n            sb.append(childName).append(child.key);\n        }\n        cur.key = sb.toString();\n        map.put(cur.key, map.getOrDefault(cur.key, 0) + 1);\n        return cur.key;\n    }\n}\n\nclass Trie {\n    String name;\n    String key;\n    Map<String, Trie> children = new HashMap<>();\n    public Trie(){};\n    public Trie(String name) {\n        this.name = name;\n    }\n}\n```
[]