lass Solution:
def evalRPN(self, tokens: List[str]) -> int:
# 后序表达式转成中序表达式
# 操作数和操作符先后入栈
op_to_binary={
'+':add,
'-':sub,
'*':mul,
'/':lambda x,y:int(x/y),
}
stack=[]
for token in tokens:
try:
num=int(token)
except ValueError:
num1=stack.pop()
num2=stack.pop()
num=op_to_binary[token](num2,num1)
finally:
stack.append(num)
return stack[0]
class Solution:
def removeDuplicateLetters(self, s: str) -> str:
unique=''.join(set(s))
# 还需要计算字典序
#先用哈希表存储字典序、字典出现的次数
# 思想是如果字符不是最后一次出现且字符比后面的字符大就不能组成字符串
info=dict()
res=[]
for ch in s:
if ch in info:
info[ch][1]+=1
else:
info[ch]=[ord(ch),1]
for ch in s:
if ch not in res:
while res and ch<res[-1] and info[res[-1]][1]>0:
res.pop()
res.append(ch)
info[ch][1]-=1
return ''.join(res)