MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / maxPathSumUtil

Function maxPathSumUtil

go/0124-binary-tree-maximum-path-sum.go:15–25  ·  view source on GitHub ↗
(root *TreeNode, arr []int)

Source from the content-addressed store, hash-verified

13}
14
15func 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
27func max(a, b int) int {
28 if a > b {

Callers 1

maxPathSumFunction · 0.85

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected