class Solution:
def isValid(self, s: str) -> bool:
hash = {'{':'}','[':']','(':')','?':'?'}
stack = ['?']
for c in s:
if c in hash:
stack.append(c)
elif hash[stack.pop()]!=c:
return False
return len(stack) ==1
class Solution:
def removeDuplicates(self, s: str) -> str:
stack = []
for w in s:
stack.append(w)
while len(stack) > 1 and stack[-1] ==stack[-2]:
stack.pop()
stack.pop()
return ''.join(stack)
class Solution:
def evalRPN(self, tokens: List[str]) -> int:
stack = []
dic = {'+':1,'-':1,'*':1,'/':1}
for c in tokens:
if c not in dic:
stack.append(int(c))
else:
if c=='+':
tmp = stack.pop() + stack.pop()
stack.append(tmp)
elif c=='-':
tmp = -stack.pop() + stack.pop()
stack.append(tmp)
elif c=='*':
tmp = stack.pop() * stack.pop()
stack.append(tmp)
elif c=='/':
tmp = 1/stack.pop() * stack.pop()
stack.append(int(tmp))
return stack[-1]
?