Beats 91 % ✅✅ C++ | pehle istemal kare fir vishwash kare ⭐😎
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<TreeNode*> ans;\n    unordered_map<int,bool> mp;\n\n    void solve(TreeNode* root,TreeNode* prev)\n    {\n         if(!root) return ;\n         TreeNode* lft = root->left;\n         TreeNode* rgt = root->right;\n         if(mp.find(root->val)!=mp.end())\n         {\n             if(prev!=NULL)\n             {\n                 if(prev->left==root) prev->left = NULL;\n                 else if(prev->right==root) prev->right = NULL;\n             }\n            root->left = NULL;\n            root->right = NULL;\n            if(lft && mp.find(lft->val)==mp.end()) ans.push_back(lft);\n            if(rgt && mp.find(rgt->val)==mp.end()) ans.push_back(rgt);\n\n            solve(lft,NULL);\n            solve(rgt,NULL);\n         }\n         else\n         {\n             solve(lft,root);\n             solve(rgt,root);\n         }\n    }\n    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n         for(auto x : to_delete) mp[x] = 1;\n         if(mp.find(root->val)==mp.end()) ans.push_back(root);\n         solve(root,NULL);\n         return ans;\n    }\n};\n```
['C++']