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)
相关推荐
IT毕设实战小研1 小时前
基于大数据的AI应用对就业与收入增长的区域差异分析及可视化
大数据·人工智能·python·随机森林·机器学习·课程设计
摆烂老大1 小时前
论文学习 | Expert Systems With Applications2026 | 可微分建模:S4D-HBV
python·学习·水文
程序员夏洛2 小时前
谈谈你了解的最常见的几种设计模式,说说他们的应用场景
开发语言·python·模板方法模式
橙露2 小时前
Cloudflare Pages 深度评测:免费静态托管的香与坑
python·部署
lk123062 小时前
【无标题】
pytorch·python
数据开发 Yang 同学2 小时前
【Python 并发编程】线程、进程、协程、同步/异步一次说清
python
程序员杰哥2 小时前
如何做接口测试?
自动化测试·python·测试工具·职场和发展·测试用例·接口测试·postman
土司大王2 小时前
LeetCode hot100——缺失的第一个正数
数据结构·算法·leetcode
weixin199701080162 小时前
[特殊字符]《从0到1:闲鱼开放平台授权登录 + AccessToken 刷新 + 聚石塔部署完整链路》(附Python源码)
java·数据库·python
Cccp.1232 小时前
【leetcode】(二)认识O(NlogN)的排序
算法·leetcode