```
def longestConsecutive(self, root):
"""
:type root: TreeNode
:rtype: int
"""
def helper(parent, root, length):
if not root:
return length
if root.val-parent.val == 1:
length += 1
else:
length = 1
return max(length, helper(root, root.left, length), helper(root, root.right, length))
if not root:
return 0
return max( helper(root, root.left, 1), helper(root, root.right, 1))
```