What's wrong with my java code?

  • 1
    This post is deleted!

  • 0

    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

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


Log in to reply

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