二叉树中的最大路径和
写一个程序,输出最大可能的路径和。
源代码:
#给定一颗二叉树,求各个路径的最大和,路径可以以任意结点作为起点和终点。
class TreeNode: #二叉树节点定义
def __init__(self, val):
self.val = val #节点值
self.left = None #左节点值
self.right = None#右节点值
class IntRef:
def __init__(self):
self.val = None
# 求a,b,c的最大值
def Max(a, b, c):
if a > b:
maxs = a
else:
maxs = b
if maxs > c