(root *TreeNode, arr []int)
| 13 | } |
| 14 | |
| 15 | func maxPathSumUtil(root *TreeNode, arr []int) int { |
| 16 | if root == nil { |
| 17 | return 0 |
| 18 | } |
| 19 | |
| 20 | left := max(0, maxPathSumUtil(root.Left, arr)) |
| 21 | right := max(0, maxPathSumUtil(root.Right, arr)) |
| 22 | arr[0] = max(arr[0], root.Val+left+right) |
| 23 | |
| 24 | return root.Val + max(left, right) |
| 25 | } |
| 26 | |
| 27 | func max(a, b int) int { |
| 28 | if a > b { |