<doocs>0549.Binary Tree Longest Consecutive Sequence II_1.py
def dfs(root):
    if root is None:
        return [0, 0]
    nonlocal ans
    incr = decr = 1
    i1, d1 = dfs(root.left)
    i2, d2 = dfs(root.right)
    if root.left:
        if root.left.val + 1 == root.val:
            incr = i1 + 1
        if root.left.val - 1 == root.val:
            decr = d1 + 1
    if root.right:
        if root.right.val + 1 == root.val:
            incr = max(incr, i2 + 1)
        if root.right.val - 1 == root.val:
            decr = max(decr, d2 + 1)
    ans = max(ans, incr + decr - 1)
    return [incr, decr]
def sample_funcname ( var_1 ) :
    if var_1 is None :
        return [ 0 , 0 ]
    nonlocal var_4
    var_7 = var_5 = 1
    var_8 , var_10 = var_0 ( var_1.left )
    var_11 , var_13 = var_0 ( var_1.right )
    if var_1.left :
        if var_1.left.val + 1 == var_1.val :
            var_7 = var_8 + 1
        if var_1.left.val - 1 == var_1.val :
            var_5 = var_10 + 1
    if var_1.right :
        if var_1.right.val + 1 == var_1.val :
            var_7 = max ( var_7 , var_11 + 1 )
        if var_1.right.val - 1 == var_1.val :
            var_5 = max ( var_5 , var_13 + 1 )
    var_4 = max ( var_4 , var_7 + var_5 - 1 )
    return [ var_7 , var_5 ]
