class Solution :
def isValid ( self, s: str ) - > bool :
stack = [ ]
for i in s:
if i in [ "[" , '(' , "{" ] :
stack. append( i)
elif stack :
temp = stack. pop( )
if ( i == ']' and temp== '[' ) or ( i == ')' and temp== '(' ) or ( i == '}' and temp== '{' ) :
continue
else :
return False
else :
return False
return False if stack else True
class Solution :
def removeDuplicates ( self, s: str ) - > str :
stack = [ ]
for i in s:
if stack and stack[ - 1 ] == i:
stack. pop( )
else :
stack. append( i)
return '' . join( stack)
class Solution :
def evalRPN ( self, tokens: List[ str ] ) - > int :
op_map = { "+" : add, '-' : sub, '*' : mul, "/" : lambda x, y: int ( x/ y) }
stack = [ ]
for i in tokens:
if i not in op_map:
stack. append( int ( i) )
else :
op1 = stack. pop( )
op2 = stack. pop( )
stack. append( op_map[ i] ( op2, op1) )
return stack[ - 1 ]