Binary Tree Pruning LeetCode solution in Python

1
class Solution:
2
def pruneTree(self, root):
3
"""
4
:type root: TreeNode
5
:rtype: TreeNode
6
"""
7
if not root:
8
return root
9
root.left, root.right = self.pruneTree(root.left), self.pruneTree(root.right)
10
return None if not root.val and not root.left and not root.right else root

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0