Python | Leetcode Python题解之第316题去除重复字母

题目:

题解:

python 复制代码
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)
相关推荐
旋生万物35 分钟前
量子纠错容错率87%?螺旋拓扑码用“相位保护“给量子比特上保险(附Python)
python·ai编程·量子计算·量子纠错·螺旋计算
用户83562907805141 分钟前
使用 Python 设置 Excel 页眉和页脚
后端·python
databook1 小时前
异常值检测与处理方法总结
python·数据挖掘·数据分析
千里码aicood1 小时前
面向智能助理的多轮医疗对话生成系统开发
python
MC皮蛋侠客1 小时前
OPC UA 系列(一):标准全景与 Python 最小闭环——让第一条设备数据流动起来
开发语言·python·opcua
用户3721574261351 小时前
使用 Python 提取 Word 文档中的表格数据
python
有味道的男人1 小时前
得物详情 API|支持实时价格、成色、鉴别服务数据
windows·python·api
小溪学编程1 小时前
Java BufferedReader 详解:从基础用法到性能优化
java·python·性能优化
2601_962300471 小时前
基于Python与Tkinter的ADB Monkey自动化测试脚本开发
python·adb·tkinter·android测试·gui自动化
SamChan901 小时前
PDF翻译后的格式完整性校验:用Python自动比对译文与原文档的表格与段落结构
开发语言·python·ai·pdf·机器翻译