Easy C++ code ( Runtime Beats 90% ) ( Memory Beats 96%)
Intuition\n Describe your first thoughts on how to solve this problem. \nWhen you delete a node store its left and right (if any) and consider it as root of a b
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhen you delete a node store its left and right (if any) and consider it as root of a binary tree \n# Approach\n<!-- Describe your approach to solving the problem. -->\nConsider a <i><b>queue</b></i>  data structure --> to store all the valid Rootnodes which are not to be deleted \n* First push root into queue and while loop exits when its empty(no nodes are left)\n* del function as return type TreeNode* to link NULL to its parent\n* Taverse from rootnode, If root->val is to be deleted store its left and right (if any) for further tranversal and retrun NULL\n*  So for every recursion call it checks for delete node and returns root if no delete node is found\n* rootnode is sorted in vector and queue is poped\n* ans vector is returned when queue is empty\n# Complexity\n- Time complexity: O(N)\nwe are traversing each node only once\n- Space complexity: O(N)\n Assuming worst case where every node is to be deleted\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    TreeNode* del(TreeNode* root,queue<TreeNode*>&Rootnodes,vector<int>&to_delete){\n        if(!root){\n            return NULL;\n        }\n        if(find(to_delete.begin(),to_delete.end(),root->val)!=to_delete.end()){\n            if(root->left){\n                Rootnodes.push(root->left);\n            }\n            if(root->right){\n                Rootnodes.push(root->right);\n            }\n            return NULL;\n        }\n        root->left=del(root->left,Rootnodes,to_delete);\n        root->right=del(root->right,Rootnodes,to_delete);\n        return root;\n    }\n    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n        vector<TreeNode*>ans;\n        queue<TreeNode*>Rootnodes;\n        Rootnodes.push(root);\n        while(!Rootnodes.empty()){\n            TreeNode* treeroot=Rootnodes.front();\n            TreeNode* rootnode=del(treeroot,Rootnodes,to_delete);\n            if(rootnode){\n                ans.push_back(rootnode);\n            }\n            Rootnodes.pop();\n        }\n        return ans;\n    }\n};\n```\nThank You :D
['C++']