Leetcode 965. Univalued Binary Tree
# 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)