python字典按值的大小排序 python text中按字典序排列最小的子序列?
python text中按字典序排列最小的子序列?类解决方案(对象):def smallestSubsequence(self,text):“””:type text:str:rtype:str“””
python text中按字典序排列最小的子序列?
类解决方案(对象):
def smallestSubsequence(self,text):
“””
:type text:str
:rtype:str
“””
stack=[
]lastu o={}
consived={}
for i in range(len(text)-1,-1,-1):
if text[i]not in lastu o:
lastu o[text[i
=i
consived[text[i
]False
打印(最后一个)
i=0
而i< len(文本):
打印(堆栈,i,文本[i])
如果len(堆栈)==0:堆栈.append(text[i])
考虑[text[i
=True
i=1
elif堆栈[-1]>text[i],并考虑[text[i
==False:
如果最后一个[stack[-1
>i:
考虑[stack[-1
=False堆栈.pop()
否则:
已考虑[text[i
=真堆栈.append(text[i])
i=1
elif堆栈[-1]<text[i],并考虑[text[i
==False:堆栈.append(text[i])
已考虑[text[i
=True
i=1
否则:
i=1
返回“”.join(堆栈中i代表i)