C++ why is using delete causing runtime error in one of the test cases?
Here\' my code:\n\n    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n        if (!root) return {};\n        vector<TreeNode*> ret;\n    
Here\' my code:\n```\n    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n        if (!root) return {};\n        vector<TreeNode*> ret;\n        unordered_set <int> del (to_delete.begin(), to_delete.end());\n        TreeNode * r = DFS(root, del, ret);\n        if (r) ret.push_back(r);\n        return ret;\n    }\n    TreeNode* DFS(TreeNode* r, unordered_set<int>& del, vector<TreeNode*>& ret){\n        if (!r) return NULL;\n        if(r->left) r->left = DFS(r->left, del, ret);\n        if(r->right) r->right= DFS(r->right, del, ret);\n        if (del.count(r->val)){\n            if(r->left) ret.push_back(r->left);\n            if(r->right) ret.push_back(r->right);\n            delete r;\n            return NULL;\n        }\n        return r;        \n    }\n```\n\nThis code is causing runtime error (apparently somewhere in the test case we are reusing the memory I freed with delete).\nThis is only happening with this test case:\n```\n4 / 111 test cases passed.\nLast executed input:\n[1,2,3,null,null,null,4]\n[2,1]\n```\n\nif i remove the delete operator the solution passses all testcases.\n\nI wonder if the driver code is reusing the root node somewhere else after calling our solution function. If that\'s the case then the driver code has a bug.
['Depth-First Search', 'C', 'C++']