classSolution(object):
创新互联是一家专业提供鄄城企业网站建设,专注与成都做网站、成都网站建设、H5响应式网站、小程序制作等业务。10年已为鄄城众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。defsmallestSubsequence(self,text):
"""
:typetext:str
:rtype:str
"""
stack=[]
last_o={}
considered={}
foriinrange(len(text)-1,-1,-1):
iftext[i]notinlast_o:
last_o[text[i]]=i
considered[text[i]]=False
print(last_o)
i=0
whilei<len(text):
print(stack,i,text[i])
iflen(stack)==0:
stack.append(text[i])
considered[text[i]]=True
i=1
elifstack[-1]>text[i]andconsidered[text[i]]==False:
iflast_o[stack[-1]]>i:
considered[stack[-1]]=False
stack.pop
else:
considered[text[i]]=True
stack.append(text[i])
i=1
elifstack[-1]<text[i]andconsidered[text[i]]==False:
stack.append(text[i])
considered[text[i]]=True
i=1
else:
i=1
return"".join(iforiinstack)