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)
相关推荐
Wyz201210242 分钟前
PyTorch bfloat16 张量转 NumPy 的正确方法与替代方案
jvm·数据库·python
weixin_580614007 分钟前
CSS如何制作下拉菜单弹性展开_利用transform-origin
jvm·数据库·python
tobias.b8 分钟前
Centos Linux 维护
linux·python·centos
m0_617881429 分钟前
如何配置Oracle WebLogic Server的JDBC数据源_JNDI查找与GridLink集群高可用连接池部署
jvm·数据库·python
weixin_458580129 分钟前
HTML函数能否用触控板高效编写_触控硬件操作体验评估【汇总】
jvm·数据库·python
weixin_3812881810 分钟前
Vue.js生命周期destroyed钩子中内存泄漏排查与资源释放
jvm·数据库·python
2301_8135995511 分钟前
C#怎么实现文件上传下载 C#如何用WebAPI实现大文件断点续传功能【网络】
jvm·数据库·python
m0_6742946412 分钟前
golang如何使用反射reflect_golang反射reflect使用教程
jvm·数据库·python
qq_3422958213 分钟前
mysql如何配置插件以提升查询性能_安装启用memcached插件
jvm·数据库·python
2401_8716965215 分钟前
c++如何实现简单的文件签名验证_HMAC-SHA1算法应用【进阶】
jvm·数据库·python