No empty tree in the testcases


  • 2
    F

    So after I ACed the problem, I looked through the discussion page
    http://discuss.leetcode.com/questions/288/binary-tree-maximum-path-sum
    and found that most of the code there does not reset the sum when the tree is empty and if it's empty, they just return Math.MIN_VALUE/MIN_INT.
    Then I took a look at the testcases and found it does not include the empty tree case.

    I think if it's empty the code should return 0 rather than a min value. Is it a bug or something? Correct me if I'm wrong please.


  • 1
    C

    No. it should return min. Because, if it returns 0, you cannot figure out there is a path which sums up to 0 or the tree is empty.


  • 0
    S

    The logic here is not right. Because if it returns min, you cannot figure out there is a path which sums up to min or the tree is empty.
    I believe the result of 0 for an empty tree makes sense in the real world also, you just choose a path that includes nothing.


Log in to reply