What is wrong with my JS solution?

  • 0
    var max=Number.MIN_VALUE;
    var maxPathSum = function(root) {
    return max;
    var helper=function(root){
    if(!root)return 0;
    var leftmax=helper(root.left);
    var rightmax=helper(root.right);
    var total=leftmax+rightmax+root.val;
    var currentmax=Math.max(total, root.val+leftmax, root.val+rightmax, root.val);
    if(currentmax > max)max=currentmax;
    return Math.max(root.val, root.val+leftmax, root.val+rightmax);


    //the case [0] won't past when I submit it...

Log in to reply

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