def longest_consecutive(root):
    """
    :type root: TreeNode
    :rtype: int
    """
    if root is None:
        return 0
    max_len = 0
    dfs(root, 0, root.val, max_len)
    return max_len
:type root: TreeNode
    :rtype: int