Binary Tree Maximum Path Sum II
Example
1
/ \
2 3Solution
"""
Definition of TreeNode:
class TreeNode:
def __init__(self, val):
this.val = val
this.left, this.right = None, None
"""
class Solution:
"""
@param root the root of binary tree.
@return an integer
"""
def maxPathSum2(self, root):
# Write your code here
if root is None:
return 0
left = self.maxPathSum2(root.left)
right = self.maxPathSum2(root.right)
return max(left, right, 0) + root.val #包含一个点就是括号外,不包含就是括号里面Last updated