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)
相关推荐
用户019027581611 小时前
AlphaFeed 查不到代码返回空?非法/缺后缀 symbol 的行为与处理
python
isfox1 小时前
Python 单元测试:别再用 print 调试了,写个测试一劳永逸
python
用户298698530141 小时前
在 Python 中把 Word 文档转换为 JSON 的三种实现方式
python·json·api
用户0332126663671 小时前
使用 Python 删除 Excel 中的空白行或空白列
python·excel
databook2 小时前
时间序列特征,哪些当时就能算出来
python·数据分析
kevin_org2 小时前
LangChain入门学习(四)
python·学习·langchain·fastapi
Pniubi3 小时前
01背包类问题-力扣416.分割等和子集
算法·leetcode·职场和发展
特立独行的猫A10 小时前
别再用 nohup 了:让应用在后台常驻的正确姿势与 systemd 服务详解
java·后端·python
吃我一窝jio13 小时前
Python与Go线程模型深度对比
java·开发语言·python
文丑颜不良啊14 小时前
LeetCode3041~3060题目解析
java·leetcode