Tap here to switch tabs
Problem
Submissions

Problem: Delete Leaves With a Given Value

Delete Leaves With a Given Value removes leaf nodes matching a target from a binary tree, including parents that become matching leaves after deletion, and returns the resulting tree.

Statement

Given the root of a binary tree and an integer target, remove all leaf nodes whose value equals target.

If deleting a leaf node causes its parent node to become a leaf node that also has a value equal to target, that parent node must also be deleted. This process repeats until no leaf nodes with the value target remain.

Return the root of the resulting binary tree.

Constraints:

  • The number of nodes in the tree is in the range [1,3000][1, 3000].

  • 1≤1 \leq Node.val, target ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Delete Leaves With a Given Value

Delete Leaves With a Given Value removes leaf nodes matching a target from a binary tree, including parents that become matching leaves after deletion, and returns the resulting tree.

Statement

Given the root of a binary tree and an integer target, remove all leaf nodes whose value equals target.

If deleting a leaf node causes its parent node to become a leaf node that also has a value equal to target, that parent node must also be deleted. This process repeats until no leaf nodes with the value target remain.

Return the root of the resulting binary tree.

Constraints:

  • The number of nodes in the tree is in the range [1,3000][1, 3000].

  • 1≤1 \leq Node.val, target ≤1000\leq 1000