💯JAVA Solution Explained in HINDI
https://youtu.be/7t7-E844m74\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote 
https://youtu.be/7t7-E844m74\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\n## Subscribe Goal:- 500\n## Current Subscriber:- 493\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private List<TreeNode> ans;\n\n    private void dfs(TreeNode root, Set<Integer> toDeleteSet, boolean isRoot) {\n        if (root == null) return;\n\n        boolean deleted = toDeleteSet.contains(root.val);\n        if (isRoot && !deleted) {\n            ans.add(root);\n        }\n\n        TreeNode leftNode = root.left;\n        TreeNode rightNode = root.right;\n\n        if (root.left != null && toDeleteSet.contains(root.left.val)) {\n            root.left = null;\n        }\n        if (root.right != null && toDeleteSet.contains(root.right.val)) {\n            root.right = null;\n        }\n\n        dfs(leftNode, toDeleteSet, deleted);\n        dfs(rightNode, toDeleteSet, deleted);\n    }\n\n    public List<TreeNode> delNodes(TreeNode root, int[] to_delete) {\n        ans = new ArrayList<>();\n        Set<Integer> toDeleteSet = new HashSet<>();\n        for (int val : to_delete) {\n            toDeleteSet.add(val);\n        }\n        dfs(root, toDeleteSet, true);\n        return ans;\n    }\n}\n```
['Java']