leetcode——965. 单值二叉树

class Solution:
    def isUnivalTree(self, root: TreeNode) -> bool:
        if not root:
            return True
        else:
            a=root.val
            if root.left and root.left.val!=a:
                return False
            elif root.right and root.right.val!=a:
                return False
            else:
                return self.isUnivalTree(root.left) and self.isUnivalTree(root.right)
执行用时 :44 ms, 在所有 python3 提交中击败了75.90%的用户
内存消耗 :13.8 MB, 在所有 python3 提交中击败了5.47%的用户
 
——2019.11.21

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11907541.html