Maximum Path Sum Binary Tree III
Last updated
Last updated
public int maxSumPath(Node root, int[] solution){
if (root == null) return 0;
int left = maxSumPath(root.left, solution);
int right = maxSumPath(root.right, solution);
int localBestPath = Math.max(root.key, root.key + Math.max(left, right);
solution[0] = Math.max(solution[0], localBestPath);
return localBestPath;
}