[Java/C++/Python] Recursion Solution
Intuition\nAs I keep saying in my video "courses",\nsolve tree problem with recursion first.\n\n\n## Explanation\nIf a node is root (has no parent) and isn\'t d
## **Intuition**\nAs I keep saying in my video "courses",\nsolve tree problem with recursion first.\n<br>\n\n## **Explanation**\nIf a `node` is root (has no parent) and isn\'t deleted,\nwhen will we add it to the `result`.\n<br>\n\n## **Complexity**\nTime `O(N)`\nSpace `O(H + N)`, where `H` is the height of tree.\n<br>\n\n**Java:**\n```java\n    Set<Integer> to_delete_set;\n    List<TreeNode> res;\n    public List<TreeNode> delNodes(TreeNode root, int[] to_delete) {\n        to_delete_set = new HashSet<>();\n        res = new ArrayList<>();\n        for (int i : to_delete)\n            to_delete_set.add(i);\n        helper(root, true);\n        return res;\n    }\n\n    private TreeNode helper(TreeNode node, boolean is_root) {\n        if (node == null) return null;\n        boolean deleted = to_delete_set.contains(node.val);\n        if (is_root && !deleted) res.add(node);\n        node.left = helper(node.left, deleted);\n        node.right =  helper(node.right, deleted);\n        return deleted ? null : node;\n    }\n```\n\n**C++:**\n```cpp\n    vector<TreeNode*> result;\n    set<int> to_delete_set;\n    vector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n        for (int i : to_delete)\n            to_delete_set.insert(i);\n        helper(root, result, to_delete_set, true);\n        return result;\n    }\n\n    TreeNode* helper(TreeNode* node, vector<TreeNode*>& result, set<int>& to_delete_set, bool is_root) {\n        if (node == NULL) return NULL;\n        bool deleted = to_delete_set.find(node->val) != to_delete_set.end();\n        if (is_root && !deleted) result.push_back(node);\n        node->left = helper(node->left, result, to_delete_set, deleted);\n        node->right =  helper(node->right, result, to_delete_set, deleted);\n        return deleted ? NULL : node;\n    }\n```\n\n**Python:**\n```python\n    def delNodes(self, root, to_delete):\n        to_delete_set = set(to_delete)\n        res = []\n\n        def helper(root, is_root):\n            if not root: return None\n            root_deleted = root.val in to_delete_set\n            if is_root and not root_deleted:\n                res.append(root)\n            root.left = helper(root.left, root_deleted)\n            root.right = helper(root.right, root_deleted)\n            return None if root_deleted else root\n        helper(root, True)\n        return res\n```\n
[]