<doocs>0008.String to Integer (atoi)_1.py
def myAtoi( s: str) -> int:
    if not s:
        return 0
    n = len(s)
    if n == 0:
        return 0
    i = 0
    while s[i] == ' ':
        i += 1
        if i == n:
            return 0
    sign = -1 if s[i] == '-' else 1
    if s[i] in ['-', '+']:
        i += 1
    res, flag = 0, (2**31 - 1) // 10
    while i < n:
        if not s[i].isdigit():
            break
        c = int(s[i])
        if res > flag or (res == flag and c > 7):
            return 2**31 - 1 if sign > 0 else -(2**31)
        res = res * 10 + c
        i += 1
    return sign * res
def sample_funcname ( var_0 : str ) -> int :
    if not var_0 :
        return 0
    var_5 = len ( var_0 )
    if var_5 == 0 :
        return 0
    var_6 = 0
    while var_0 [ var_6 ] == ' ' :
        var_6 += 1
        if var_6 == var_5 :
            return 0
    var_10 = - 1 if var_0 [ var_6 ] == '-' else 1
    if var_0 [ var_6 ] in [ '-' , '+' ] :
        var_6 += 1
    var_12 , var_16 = 0 , ( 2 ** 31 - 1 ) // 10
    while var_6 < var_5 :
        if not var_0 [ var_6 ].isdigit ( ) :
            break
        var_18 = int ( var_0 [ var_6 ] )
        if var_12 > var_16 or ( var_12 == var_16 and var_18 > 7 ) :
            return 2 ** 31 - 1 if var_10 > 0 else - ( 2 ** 31 )
        var_12 = var_12 * 10 + var_18
        var_6 += 1
    return var_10 * var_12
