814. Binary Tree Pruning
https://leetcode.com/problems/binary-tree-pruning/
Python
Postfix Traversal
class Solution:
def pruneTree(self, node: Optional[TreeNode]) -> Optional[TreeNode]:
if not node:
return
node.left = self.pruneTree(node.left)
node.right = self.pruneTree(node.right)
if node.val == 0 and not node.left and not node.right:
return
return node