Python Fast Solution


  • 0
    D
    while expression:
                first = expression[0]
                if len(expression) == 1: return first
                questions, i = 1, 3
                while questions != 0 :
                    if expression[i] == '?': questions += 1
                    if expression[i] == ':': questions -= 1
                    i += 1
                if first == 'T':
                    expression = expression[2:i-1]
                else:
                    expression = expression[i:]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.