What's wrong with my java code?


  • 1
    B
    This post is deleted!

  • 0
    S

    The problem here is, if say, right.val is val + 1, then it assumes longestConsecutive(root.right) + 1 to be the value of the current node, where as the return of longestConsecutive gives the value of the sequence that may NOT start from the right node, instead it might be from descendent of the right node. so your method over count the result.


  • 1
    X

    Try this test case, and then you'll know why

    [1,null,2,null,4,null,5,null,6]


Log in to reply
 

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