beats 97.77%
\n\n# Code\njava []\nclass Solution {\n    class Node {\n        Map<String, Node> subNodes = new TreeMap<>();\n\n        String content = "";\n\n        boolea
\n\n# Code\n```java []\nclass Solution {\n    class Node {\n        Map<String, Node> subNodes = new TreeMap<>();\n\n        String content = "";\n\n        boolean remove = false;\n\n        void markRemove() {\n            if (remove) {\n                return;\n            }\n            remove = true;\n            if (subNodes != null) {\n                for (Node value : subNodes.values()) {\n                    value.markRemove();\n                }\n            }\n        }\n    }\n\n    public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {\n        paths.sort(Comparator.comparingInt(List::size));\n        List<Node> nodes = new ArrayList<>(paths.size());\n        Node rootNode = new Node();\n        for (List<String> pathList : paths) {\n            Node current = rootNode;\n            int last = pathList.size() - 1;\n            for (int i = 0; i < last; i++) {\n                String s = pathList.get(i);\n                current = current.subNodes.get(s);\n            }\n            String name = pathList.get(last);\n            Node node = new Node();\n            current.subNodes.put(name, node);\n            nodes.add(node);\n        }\n        StringBuilder content = new StringBuilder();\n        Map<String, Node> nodeByContent = new HashMap<>();\n        for (int i = nodes.size() - 1; i >= 0; i--) {\n            Node node = nodes.get(i);\n            if (node.subNodes.isEmpty()) {\n                continue;\n            }\n            for (Map.Entry<String, Node> entry : node.subNodes.entrySet()) {\n                content.append(entry.getKey()).append(\'{\').append(entry.getValue().content).append(\'}\');\n            }\n            node.content = content.toString();\n            content.delete(0, content.length());\n            Node similar = nodeByContent.putIfAbsent(node.content, node);\n            if (similar != null) {\n                node.markRemove();\n                similar.markRemove();\n            }\n        }\n        List<List<String>> ans = new ArrayList<>();\n        for (int i = 0; i < paths.size(); i++) {\n            if (!nodes.get(i).remove) {\n                ans.add(paths.get(i));\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']