标签:
题目: 124 Binary Tree Maximum Path Sum
这道题就是分别算出左子树和右子树的可能最大和,然后对Path的值进行更新即可
class Solution: def __init__(self): self.ans = -100000 def maxPathSum(self, root): self.getSum(root) return self.ans def getSum(self, root): if not root: return 0 left = max(0, self.getSum(root.left)) right = max(0, self.getSum(root.right)) self.ans = max(self.ans, left + root.val + right) return root.val + max(left,right)
124 Binary Tree Maximum Path Sum
标签:
原文地址:http://www.cnblogs.com/dapanshe/p/4648001.html