LeetCode — Binary Tree Pruning

Input: root = [1,null,0,0,1]
Output: [1,null,0,null,1]
Explanation:
Only the red nodes satisfy the property "every subtree not containing a 1".
The diagram on the right represents the answer.
Input: root = [1,0,1,0,0,0,1]
Output: [1,null,1,null,1]
Input: root = [1,1,0,1,1,0,1,0]
Output: [1,1,0,1,1,null,1]
  • The number of nodes in the tree is in the range [1, 200].
  • Node.val is either 0 or 1.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store