标签:das elf col return div res ash longest bsp
class Solution: def longestUnivaluePath(self, root: TreeNode) -> int: self.ans=0 def arrow_length(node): if not node: return 0 left_length=arrow_length(node.left) right_length=arrow_length(node.right) left_arrow=right_arrow=0 if node.left and node.left.val==node.val: left_arrow=left_length+1 if node.right and node.right.val==node.val: right_arrow=right_length+1 self.ans=max(self.ans,left_arrow+right_arrow) return max(left_arrow,right_arrow) arrow_length(root) return self.ans
标签:das elf col return div res ash longest bsp
原文地址:https://www.cnblogs.com/taoyuxin/p/11907719.html