Java Tire , DFS, HashMap :: 100% faster
Here first we have build trie tree insert() .\nThen we have dfs the whole tree and stored the child part into String dfsTrie() .\nIf the string is repeating we 
Here first we have build trie tree *insert()* .\nThen we have dfs the whole tree and stored the child part into String *dfsTrie()* .\nIf the string is repeating we have set the the value to true. and we have used hashmap to to detect the repetation.\nThen we have used the remove node method there we check is the if the string is repetaing if yes then we remove the node else we dfs to next node .*removeNode()*\nThen we have use simple dfs on whole tree to generate the answer *getAnswer()*.\n\n```\nclass Solution {\n    \n    public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {\n        Trie node = new Trie("/");\n        for (List<String> val : paths) {\n            insert(node, val);\n        }\n        HashMap<String, Boolean> map = new HashMap<>();\n        dfsTrie(node, map);\n        removeNode(node, map);\n        List<List<String>> ans = new ArrayList<>();\n        getAnswer(node, new LinkedList<>(), ans);\n        return ans;\n\n    }\n\n    void insert(Trie node, List<String> paths) {\n        for (String a : paths) {\n            if (node.next.get(a) == null) {\n                node.next.put(a, new Trie(a));\n            }\n            node = node.next.get(a);\n        }\n    }\n\n    String dfsTrie(Trie node, HashMap<String, Boolean> map) {\n        StringBuilder sb = new StringBuilder();\n        for (Trie val : node.next.values()) {\n            if (val != null) {\n                String rec = dfsTrie(val, map);\n                if (rec.length()>0 && map.containsKey(rec)) {\n                    map.put(rec, true);\n                } else {\n                    map.put(rec, false);\n                }\n                sb.append(rec + val.a);\n            }\n        }\n        node.dirName = sb.toString();\n        return sb.toString();\n    }\n\n    void removeNode(Trie node, HashMap<String, Boolean> map) {\n        for (Map.Entry<String,Trie> val : node.next.entrySet() ) {\n            if (val.getValue().dirName != null && map.get(val.getValue().dirName)) {\n                node.next.put(val.getKey(), null);\n            }\n            if (node.next.get(val.getKey()) != null) {\n                removeNode(node.next.get(val.getKey()), map);\n            }\n        }\n    }\n\n    void getAnswer(Trie node, LinkedList<String> res, List<List<String>> ans) {\n        for (Trie val : node.next.values()) {\n            if (val != null) {\n                res.add(val.a + "");\n                ans.add(new ArrayList<>(res));\n                getAnswer(val, res, ans);\n                res.removeLast();\n            }\n        }\n    }\n\n    class Trie {\n        String a;\n        HashMap<String, Trie> next;\n        String dirName;\n\n        Trie(String a) {\n            this.a = a;\n            this.next = new HashMap<>();\n            dirName = null;\n        }\n    }\n\n}\n```
['Tree', 'Depth-First Search', 'Trie', 'Java']