21. Delete Nodes And Return Forest
Last updated
Was this helpful?
Last updated
Was this helpful?
Given the root
of a binary tree, each node in the tree has a distinct value.
After deleting all nodes with a value in to_delete
, we are left with a forest (a disjoint union of trees).
Return the roots of the trees in the remaining forest. You may return the result in any order.
Example 1:
Example 2:
Delete operation works only on NULL pointer
Time Complexity: O(n)