# java Someone please help me look at my code. I do not know where is the problem.


  • 0

    Someone please help me look at my code. I do not know where is the problem.
    '''
    public class Solution {
    public int maxPathSum(TreeNode root) {
    int max = Integer.MIN_VALUE;
    maxPathSum(root, max);
    return max;
    }
    private int maxPathSum(TreeNode node, int max){
    if(node == null) return 0;
    int left = Math.max(0, maxPathSum(node.left, max));
    int right = Math.max(0, maxPathSum(node.right, max));
    max = Math.max(max, left + right +node.val);
    return Math.max(left, right) + node.val;
    }

    }
    '''


  • 0
    Y

    Your private helper function should have a different name like maxPathSumHelper.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.