IT评测·应用市场-qidao123.com
标题:
Python | Leetcode Python题解之第316题去除重复字母
[打印本页]
作者:
一给
时间:
2024-8-5 04:32
标题:
Python | Leetcode Python题解之第316题去除重复字母
题目:
题解:
class Solution:
def removeDuplicateLetters(self, s: str) -> str:
vis = defaultdict(int)
cnt = defaultdict(int)
for ch in s: cnt[ch] += 1
queue = []
for ch in s:
if vis[ch] == 0:
while queue and queue[-1] > ch and cnt[queue[-1]]:
vis[queue.pop()] = 0
if not queue or queue != ch: queue.append(ch)
vis[ch] = 1
cnt[ch] -= 1
return "".join(queue)
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/)
Powered by Discuz! X3.4