2019年3月18日 814. Binary Tree Pruning

递归题

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def pruneTree(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        if root == None:
            return None
        
        root.left = self.pruneTree(root.left)
        root.right = self.pruneTree(root.right)
            
        if root.left is None and root.right is None and root.val != 1:
            return None
    
        return root
posted @ 2019-03-18 09:23  miuc  阅读(134)  评论(0编辑  收藏  举报