# 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)
Leetcode 965. Univalued Binary Tree
猜你喜欢
转载自www.cnblogs.com/zywscq/p/10681020.html
今日推荐
周排行