标签:type code 哨兵 dup self elf ash count style
这道题也不是我自己想出来的。。。
class Solution(object): def removeDuplicateLetters(self, s): """ :type s: str :rtype: str """ counts = {} coun=set(s) for c in coun: counts[c]=s.count(c) stack, stacked = [‘0‘], set() # stack为答案,放置哨兵,stacked为stack中已有的字符 for c in s: if c not in stacked: while c < stack[-1] and counts[stack[-1]]: # 当栈顶在后面还有且大于当前字符时弹出 stacked.remove(stack.pop()) stack.append(c) stacked.add(c) counts[c] -= 1 return ‘‘.join(stack[1:])
标签:type code 哨兵 dup self elf ash count style
原文地址:https://www.cnblogs.com/taoyuxin/p/11793009.html