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

@functools.lru_cache()
class Solution:
    def isUnivalTree(self, root: TreeNode) -> bool:
        return self.same(root.left,root.val) and self.same(root.right,root.val)
        
    def same(self,root:TreeNode,val:int)->bool:
        if not root:
            return True
        if root.val!=val:
            return False
        return self.same(root.left,val) and self.same(root.right,val)
        
        

 

相关文章:

  • 2022-01-10
  • 2021-12-24
  • 2022-02-24
  • 2021-11-06
  • 2021-12-22
  • 2021-08-25
  • 2022-02-02
猜你喜欢
  • 2021-11-17
  • 2021-11-25
  • 2022-01-20
  • 2021-11-26
  • 2021-08-06
  • 2021-04-15
相关资源
相似解决方案