Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions 124. Binary Tree Maximum Path Sum.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
*/
public class Solution {
int max = Integer.MIN_VALUE;

public int maxPathSum(TreeNode root) {
maxPathSumUtil(root);
return max;
}

public int maxPathSumUtil(TreeNode node){
if(node == null)
return 0;
if(node == null){
return 0;}
int l = maxPathSumUtil(node.left);
int r = maxPathSumUtil(node.right);
int retval = node.val+l > node.val+r ? node.val+l : node.val+r;
Expand Down