<doocs>0678.Valid Parenthesis String_1.py
def checkValidString( s: str) -> bool:
    n = len(s)
    left, asterisk = 0, 0
    for i in range(n):
        if s[i] == "(":
            left += 1
        elif s[i] == ")":
            if left > 0:
                left -= 1
            elif asterisk > 0:
                asterisk -= 1
            else:
                return False
        else:
            asterisk += 1
    right, asterisk = 0, 0
    for i in range(n - 1, -1, -1):
        if s[i] == ")":
            right += 1
        elif s[i] == "(":
            if right > 0:
                right -= 1
            elif asterisk > 0:
                asterisk -= 1
            else:
                return False
        else:
            asterisk += 1
    return True
def sample_funcname ( var_0 : str ) -> bool :
    var_4 = len ( var_0 )
    var_6 , var_7 = 0 , 0
    for var_9 in range ( var_4 ) :
        if var_0 [ var_9 ] == "(" :
            var_6 += 1
        elif var_0 [ var_9 ] == ")" :
            if var_6 > 0 :
                var_6 -= 1
            elif var_7 > 0 :
                var_7 -= 1
            else :
                return False
        else :
            var_7 += 1
    var_14 , var_7 = 0 , 0
    for var_9 in range ( var_4 - 1 , - 1 , - 1 ) :
        if var_0 [ var_9 ] == ")" :
            var_14 += 1
        elif var_0 [ var_9 ] == "(" :
            if var_14 > 0 :
                var_14 -= 1
            elif var_7 > 0 :
                var_7 -= 1
            else :
                return False
        else :
            var_7 += 1
    return True
