(C++) 1948. Delete Duplicate Folders in System
\n\nclass Node {\npublic: \n    bool mark = false; \n    int index = -1; \n    unordered_map<string, Node*> next; \n};\n\nclass Solution {\npublic:\n    vector<
\n```\nclass Node {\npublic: \n    bool mark = false; \n    int index = -1; \n    unordered_map<string, Node*> next; \n};\n\nclass Solution {\npublic:\n    vector<vector<string>> deleteDuplicateFolder(vector<vector<string>>& paths) {\n        sort(paths.begin(), paths.end());\n        \n        Node* tree = new Node(); \n        for (int i = 0; i < paths.size(); ++i) {\n            Node* node = tree; \n            for (auto& x : paths[i]) {\n                if (node->next.count(x) == 0) node->next[x] = new Node(); \n                node = node->next[x]; \n            }\n            node->index = i; \n        }\n        \n        unordered_map<string, vector<int>> mp; \n        \n        function<string(Node*)> fn = [&](Node* node) -> string {\n            if (node->next.size() == 0) return "$"; \n            string ans; \n            for (auto& [k, nn] : node->next) \n                ans += "$" + k + "$" + fn(nn); \n            mp[ans].push_back(node->index); \n            return ans; \n        };\n        \n        fn(tree); \n        \n        unordered_set<int> mark; \n        for (auto& [k, v] : mp) \n            if (v.size() > 1) \n                for (auto& vv : v) mark.insert(vv); \n        \n        vector<vector<string>> ans; \n        stack<Node*> stk; \n        stk.push(tree); \n        \n        while(stk.size()) {\n            Node* node = stk.top(); stk.pop(); \n            if (node->index >= 0) ans.push_back(paths[node->index]); \n            for (auto& [k, nn] : node->next) {\n                if (mark.find(nn->index) == mark.end()) \n                    stk.push(nn); \n            }\n        }\n        return ans; \n    }\n};\n```
['C']