maximum = 0


def maxPathSum(self, A):
    global maximum
    if not A:
        return 0
    val = A.val + self.maxPathSum(A.left) + self.maxPathSum(A.right)
    if val > maximum:
        maximum = val
    return maximum

1caef96820af02fdf1be4ca43d335d0ea2290699
<mask token>

<mask token>


def maxPathSum(self, A):
    global maximum
    if not A:
        return 0
    val = A.val + self.maxPathSum(A.left) + self.maxPathSum(A.right)
    if val > maximum:
        maximum = val
    return maximum

maximum = 0


def maxPathSum(self, A):
    global maximum
    if not A:
        return 0
    val = A.val + self.maxPathSum(A.left) + self.maxPathSum(A.right)
    if val > maximum:
        maximum = val
    return maximum
