👍Runtime 383 ms Beats 100.00%
Code\n\ntype Node struct {\n\tsubNodes map[string]*Node\n\tcontent  string\n\tremove   bool\n}\n\nfunc newNode() *Node {\n\treturn &Node{\n\t\tsubNodes: make(ma
# Code\n```\ntype Node struct {\n\tsubNodes map[string]*Node\n\tcontent  string\n\tremove   bool\n}\n\nfunc newNode() *Node {\n\treturn &Node{\n\t\tsubNodes: make(map[string]*Node),\n\t}\n}\n\nfunc (node *Node) markRemove() {\n\tif node.remove {\n\t\treturn\n\t}\n\tnode.remove = true\n\tfor _, value := range node.subNodes {\n\t\tvalue.markRemove()\n\t}\n}\n\nfunc deleteDuplicateFolder(paths [][]string) [][]string {\n\t// Sort paths by their length\n\tsort.Slice(paths, func(i, j int) bool {\n\t\treturn len(paths[i]) < len(paths[j])\n\t})\n\n\tnodes := make([]*Node, len(paths))\n\trootNode := newNode()\n\n\tfor i, pathList := range paths {\n\t\tcurrent := rootNode\n\t\tlast := len(pathList) - 1\n\t\tfor j := 0; j < last; j++ {\n\t\t\ts := pathList[j]\n\t\t\tif _, exists := current.subNodes[s]; !exists {\n\t\t\t\tcurrent.subNodes[s] = newNode()\n\t\t\t}\n\t\t\tcurrent = current.subNodes[s]\n\t\t}\n\t\tname := pathList[last]\n\t\tnode := newNode()\n\t\tcurrent.subNodes[name] = node\n\t\tnodes[i] = node\n\t}\n\n\tcontent := strings.Builder{}\n\tnodeByContent := make(map[string]*Node)\n\n\tfor i := len(nodes) - 1; i >= 0; i-- {\n\t\tnode := nodes[i]\n\t\tif len(node.subNodes) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tfor key, value := range node.subNodes {\n\t\t\tcontent.WriteString(key)\n\t\t\tcontent.WriteString("{")\n\t\t\tcontent.WriteString(value.content)\n\t\t\tcontent.WriteString("}")\n\t\t}\n\t\tnode.content = content.String()\n\t\tcontent.Reset()\n\t\tif similar, exists := nodeByContent[node.content]; exists {\n\t\t\tnode.markRemove()\n\t\t\tsimilar.markRemove()\n\t\t} else {\n\t\t\tnodeByContent[node.content] = node\n\t\t}\n\t}\n\n\tvar ans [][]string\n\tfor i, path := range paths {\n\t\tif !nodes[i].remove {\n\t\t\tans = append(ans, path)\n\t\t}\n\t}\n\n\treturn ans\n}\n```
['Go']