Problem :

https://leetcode.com/problems/binary-tree-maximum-path-sum/


My Solution :

# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None

class Solution:
def maxPathSum(self, root: TreeNode) -> int:
def find(root):
if root:
left = find(root.left)
right = find(root.right)
self.ans = max(self.ans, root.val + left + right)
return max(0, root.val + max(left, right))
return 0

self.ans = root.val
find(root)
return self.ans