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
posted @ 2019-11-21 18:56  欣姐姐  阅读(116)  评论(0编辑  收藏  举报