MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / maxiPathSum

Method maxiPathSum

TreeMaximumPathSumBinaryTree.java:9–17  ·  view source on GitHub ↗
(TreeNode root, int arr[])

Source from the content-addressed store, hash-verified

7 }
8
9 public int maxiPathSum(TreeNode root, int arr[])
10 {
11 if(root == null ) return 0;
12
13 int leftSum = Math.max(maxiPathSum(root.left,arr),0);
14 int rightSum = Math.max(maxiPathSum(root.right,arr),0);
15 arr[0] = Math.max(arr[0],root.val + leftSum+rightSum);
16 return root.val + Math.max(leftSum,rightSum);
17 }
18}

Callers 1

maxPathSumMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected