[Java] Simple Trie + DFS Solution
Code\n\nclass Solution {\n    class TrieNode {\n        TreeMap<String, TrieNode> children;\n        boolean isEndOfDir;\n        boolean deleted;\n        \n  
# Code\n```\nclass Solution {\n    class TrieNode {\n        TreeMap<String, TrieNode> children;\n        boolean isEndOfDir;\n        boolean deleted;\n        \n        public TrieNode() {\n            children = new TreeMap<>();\n            isEndOfDir = false;\n            deleted = false;\n        }\n    }\n\n    public void insert(TrieNode root, List<String> path) {\n        TrieNode cur = root;\n        \n        for(int depth=0; depth<path.size(); depth++) {\n            String ch = path.get(depth);\n            \n            if(!cur.children.containsKey(ch)) {\n                cur.children.put(ch, new TrieNode());\n            }\n            \n            cur = cur.children.get(ch);\n        }\n        \n        cur.isEndOfDir = true;\n        \n    }\n\n    TrieNode root;\n    HashMap<String, ArrayList<TrieNode>> hm;\n    List<List<String>> ansLst;\n    \n    public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {\n        root = new TrieNode();\n        hm = new HashMap<>();\n        ansLst = new ArrayList<>();\n\n        for(int i=0; i<paths.size(); i++) {\n            insert(root, paths.get(i));\n        }\n\n        // Store all the child structures of Nodes in HashMap\n        dfs(root);\n\n        // If the node has the same child structure with other nodes,\n        // make node.deleted = true.\n        for(String key : hm.keySet()) {\n            if(hm.get(key).size() > 1) {\n                for(TrieNode node : hm.get(key)) {\n                    node.deleted = true;\n                }\n            }\n        }\n\n        // Traverse to store survived Nodes in the Trie.\n        helper(root, new ArrayList<>());\n\n        return ansLst;   \n    }\n\n    public void helper(TrieNode root, ArrayList<String> lst) {\n        if(root.deleted) return;\n\n        for(String key: root.children.keySet()) {\n            lst.add(key);\n            helper(root.children.get(key), lst);\n            lst.remove(lst.size()-1);\n        }\n\n        if(lst.size() > 0) {\n            ArrayList<String> tmp = new ArrayList<>();\n            for(String s : lst) {\n                tmp.add(s);\n            }\n            ansLst.add(tmp);\n        }\n    }\n\n    public String dfs(TrieNode root) {\n        StringBuilder sb = new StringBuilder();\n        \n        for(String key: root.children.keySet()) {\n            sb.append(key + "#");\n        }\n\n        for(String key: root.children.keySet()) {\n            sb.append("$" + dfs(root.children.get(key)));\n        }\n                \n        if(!hm.containsKey(sb.toString())) {\n            hm.put(sb.toString(), new ArrayList<>());\n        }\n\n        if(sb.toString().length() > 0) {\n            hm.get(sb.toString()).add(root);\n        }\n\n        return sb.toString();\n    }\n}\n```
['Java']