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)
相关推荐
李可以量化2 分钟前
Tornado 从入门到精通(二)下:协程调用方式与经典使用模式
python
雪碧透心凉_11 分钟前
Python OpenCV图像处理入门
图像处理·python·opencv
李可以量化25 分钟前
Tornado 从入门到精通(二)上:协程核心机制详解
python
晴天1628 分钟前
AgentLoop分享(上): 让 AI 真正“自主干活“-Day15
人工智能·python
Patrick在香港36 分钟前
Python爬虫框架实战:优雅抓取香港政府公开API数据的通用方案
java·开发语言·爬虫·python·ai编程·数据可视化·可用性测试
李白的天不白1 小时前
python下载脚本
python
2501_909509101 小时前
DAY 45
python
郝学胜_神的一滴1 小时前
Python 高级编程 027:四大推导式全攻略
python·pycharm
wabs6661 小时前
关于哈希表【力扣15.三数之和的思考】
数据结构·算法·leetcode·散列表·哈希表·三数之和
菜冻鱼1 小时前
Python-sklearn-特征工程
开发语言·人工智能·python·机器学习·numpy·matplotlib·sklearn