<doocs>0687.Longest Univalue Path_1.py
def dfs(root):
    if root is None:
        return 0
    left, right = dfs(root.left), dfs(root.right)
    left = left + 1 if root.left and root.left.val == root.val else 0
    right = right + 1 if root.right and root.right.val == root.val else 0
    nonlocal ans
    ans = max(ans, left + right)
    return max(left, right)
def sample_funcname ( var_1 ) :
    if var_1 is None :
        return 0
    left , right = var_0 ( var_1.left ) , var_0 ( var_1.right )
    left = left + 1 if var_1.left and var_1.left.val == var_1.val else 0
    right = right + 1 if var_1.right and var_1.right.val == var_1.val else 0
    nonlocal var_8
    var_8 = max ( var_8 , left + right )
    return max ( left , right )
