Binary Tree Pruning LeetCode solution in Python
1class Solution:2def pruneTree(self, root):3"""4:type root: TreeNode5:rtype: TreeNode6"""7if not root:8return root9root.left, root.right = self.pruneTree(root.left), self.pruneTree(root.right)10return None if not root.val and not root.left and not root.right else root