Recursively deleting nodes bottom up [C++] (with comments) - Faster than 99.96%
\nstatic const auto ____ = [](){\n\t// fast I/O\n    ios_base::sync_with_stdio(false);\n    cin.tie(nullptr), cout.tie(nullptr);\n    return 0;\n}();\n\n// Runt
```\nstatic const auto ____ = [](){\n\t// fast I/O\n    ios_base::sync_with_stdio(false);\n    cin.tie(nullptr), cout.tie(nullptr);\n    return 0;\n}();\n\n// Runtime - 16 ms, Memory - 22.6 MB\nclass Solution {\n    unordered_set<int> del;\n    vector<TreeNode *> res;\n    \npublic:\n    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n        for(const int &x: to_delete)    del.insert(x);\n        \n        dfs(root);\n        // if main tree root is not to be deleted then add that remaining tree to result\n        if(root != nullptr && del.count(root->val) == 0)    res.emplace_back(root);\n        return res;\n    }\n    \n    // traverse down to leaf nodes and check hashset to delete nodes and add children to result recursively\n    void dfs(TreeNode *&root) {\n        if(root == nullptr)     return;\n        \n        dfs(root->left);\n        dfs(root->right);\n        \n        if(root != nullptr && del.count(root->val) == 1) {\n            if(root->left != nullptr)   res.emplace_back(root->left);\n            if(root->right != nullptr)  res.emplace_back(root->right);\n            root = nullptr;\n        }\n    }\n};\n```
[]