# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def maxPathSum(self, root: TreeNode) -> int: return self.maxPathhelper(root)[1] def maxPathhelper(self, root): if root == None: return 0, float('-inf') left = self.maxPathhelper(root.left) right = self.maxPathhelper(root.right) singlePath = max(left[0], right[0]) + root.val singlePath = max(singlePath, 0) #important line!!! maxPath = max(left[1], right[1], left[0] + right[0] + root.val) return singlePath, maxPath