LeetCode 316. Remove Duplicate Letters

L2tp环境搭建笔记- Openwrt平台 本文使用3台openwrt设备, 分别搭建L2TP服务和2个客户端, 进行端到端验证和局域网组网,并分析搭建过程中涉及的默认路由( defaultroute) 配置问题。 阅读详情

有点奇怪的一道题 题意是将字符串s内出现的每种字母只保留一个 并要求字典序最小

有点类似优先队列的思想,遍历s的同时维护一个结果串ans,当出现未访问过的字符c时,从后往前查看结果串的字符,如果结果串ans当前的字符cc,满足cc>c 并且原串s后面还会出现cc,就把cc删除。从后往前删除所有这样的cc后,把c添加到ans的末尾。

最后ans就是答案

class Solution {
    public String removeDuplicateLetters(String s) {
        int []num = new int[26];
        int []vis = new int[26];
        StringBuffer ans = new StringBuffer("");
        for(int i=0;i<s.length();i++){
            num[s.charAt(i)-'a']++;
        }
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            if(ans.equals("")){
                ans.append(c);
                num[c-'a']--;
                vis[c-'a']=1;
                continue;
            }
            if(vis[c-'a']==1){
                num[c-'a']--;
                continue;
            }
            int j=ans.length()-1;
            while(j>=0){
                char cc = ans.charAt(j);
                if(cc<c || num[cc-'a']==0)
                    break;
                vis[cc-'a']=0;
                ans.deleteCharAt(ans.length()-1);
                j--;
            }
            ans.append(c);
            vis[c-'a']=1;
            num[c-'a']--;
        }
        return ans.toString();
    }
}

番外篇 | 关于YOLO11算法的改进点总结 关于YOLO11算法的改进点总结。🌈 阅读详情

相关推荐

告别‘火龙’:实测BES2800/RK2108等主流芯片,聊聊AI眼镜的功耗与散热‘内卷’实战

本文深入探讨了AI智能眼镜在功耗与散热方面的挑战,重点分析了恒玄BES2800和瑞芯微RK2108等主控芯片的能效表现。通过实测数据和优化策略,揭示了在6nm工艺、异构计算和系统级散热方案下的实战经验,为AI眼镜的功耗管理提供了实用解决方案。

weixin_30839881的博客 946

LeetCode: 316. Remove Duplicate Letters

LeetCode: 316. Remove Duplicate Letters 题目描述 Given a string which contains only lowercase letters, remove duplicate letters so that every letter appears once and only once. You must make sure your res...

杨领well的专栏 277

华硕笔记本键盘失灵恢复方法全解析

华硕笔记本键盘失灵问题可能由多种原因导致,但大多数问题都可以通过上述方法得到解决。在尝试恢复键盘功能时,请务必按照步骤操作,并注意备份重要数据。如果问题依然存在,请寻求专业维修人员的帮助。希望本文能够帮助大家快速解决华硕笔记本键盘失灵的问题!

mmoo_python的博客 4227

LeetCode #316 Remove Duplicate Letters

文章目录题目分析贪心算法 (Week 9 算法博客) 题目 Remove Duplicate Letters Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure...

Blog of SquirrelYuyu 810

K-means在关键词聚类中的尝试

K-means在文本聚类中的尝试 K-means算法是无监督的聚类算法。它的算法思想是:先随机选取K个对象作为初始的聚类中心。然后计算每个对象与各个种子聚类中心之间的距离,把每个对象分配给距离它最近的聚类中心。聚类中心以及分配给它们的对象就代表一个聚类。一旦全部对象都被分配了,每个聚类的聚类中心会根据聚类中现有的对象被重新计算。 K-means算法的关键点在于: 初始k个聚类中心的选择 距离的计...

BigPig_LittleTail的博客 5573

力软敏捷开发框架源码7.0.6旗舰版 JNPF开发平台3.4.5 企业版 旗舰版

JNPF作为作为一款深受用户喜爱的低代码产品,凭借雄厚的科研技术力量、丰富的软件开发项目经验、严谨的项目开发流程和高质量的售后服务,已成功帮助千家企业完成数字化项目,建立了覆盖不同行业客户和不同发展阶段的软件产品服务体系。

huoooos0的博客 1839

Leetcode 316 Remove Duplicate Letters

Leetcode 316 Remove Duplicate Letters题目代码 题目 Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Note: This question

weixin_43796689的博客 172

手把手教你学 AI芯片 SOC软件开发专栏简介

在AI芯片(如NPU、GPU加速器)爆发式增长的今天,软件栈开发已成为AI应用落地的核心瓶颈。无论是模型推理加速、低延迟部署,还是能效优化,都依赖于对芯片底层软件的深度掌握。然而,许多开发者困于“只会调用API,不懂驱动实现”的困境,导致性能瓶颈难以突破。本专栏《手把手教你学 AI芯片 SOC软件开发》专为AI工程师、嵌入式开发者及系统架构师打造,从零基础切入,系统拆解AI芯片SOC(System on Chip)的完整软件栈,覆盖Runtime(运行时)

MHD0815的博客 171

leetcode 316 Remove Duplicate Letters

lc316 Remove Duplicate Letters 我们用一个栈来保存最终的返回结果, 现在来看看什么时候能删除一个元素,bcabc走到a的时候发现c大于a而且a后还有c,所以可以删除 由此可见,当array[i]之前的字母较大,且在i之后还有重复的字母,就能删除 如何实现这个逻辑呢?    1) 统计各个字母出现次数abc[26]   2) count[array[i]]-...

weixin_30548917的博客 128

把复杂计算推到数据库里:ABAP CDS View Table Function 从原理到落地实践

摘要:本文深入解析ABAP CDS Table Function技术,重点探讨其在复杂业务场景下的应用价值。当CDS View无法满足窗口函数、递归计算等高级需求时,Table Function通过结合CDS类型系统与AMDP的数据库原生计算能力,成为关键解决方案。文章详细介绍了Table Function的架构设计(CDS实体声明+AMDP实现)、客户端处理机制、开发传输流程中的注意事项,并通过航班数据示例展示最小实现闭环。这项技术特别适用于需要将复杂计算下推到数据库层的场景,能显著提升RAP和OData

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2294

向华为学习——解读华为战略规划SP与业务计划BP流程【附全文阅读】

该方案针对大中型企业高管及战略团队,系统拆解华为SP(4-9月中长期规划)与BP(10-12月年度执行)双轨体系,形成"战略制定-业务设计-资源配置-绩效解码"闭环。SP侧重市场趋势分析、业务优先级与资源分配,BP细化KPI、预算及行动计划。通过价值树、战略解码等工具实现战略到部门/个人的目标分解,强化跨部门协同与过程管控。配套17份华为实战资料(包括战略管理、流程优化、销售组织建设等核心方法论),助力企业建立规范的战略执行体系,实现资源优化与绩效落地。

cdfunlove的博客 768

[leetcode-316]Remove Duplicate Letters

该题思路有两种,一种是将string当做stack处理,另一种是贪婪算法 class Solution { public: string removeDuplicateLetters(string s) { bool inRes[26] = {false}; int counts[26] = {0}; for (auto

100120101的博客 1425

2. Android_逆向的历史与发展

学完本节,希望你能够:了解 Android 逆向工程的发展历程,从早期 APK 破解到现代应用保护;入门先把这几类「在干啥」搞清楚,后面学脱壳、反反调试会顺很多。(反编译 APK 得到的类汇编代码,相当于程序的「菜谱」)就能绕过验证,到后来混淆、加固、反调试一起上,逆向难度越来越高。(第三节 什么是 CPU 指令集),帮你搞清楚「反汇编看到的那些指令」是从哪来的、和 Android 逆向有啥关系。有必要——先搞清「没加固时怎么玩」,再学脱壳和对抗,思路才顺。读起来费劲,但逻辑还在,耐心一点还能跟。

长沙火山 1390

[LeetCode 316] Remove Duplicate Letters

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a

coder 进阶的专栏 5205

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

leetcode - 316. Remove Duplicate Letters

算法系列博客之Greedy Greedy 贪心算法是一种非常优美的算法,不过贪心算法本身的可行性很多时候会受到一些局限。但是一旦能够找到一种可行的贪心策略,问题的解决将会变得非常高效,因为通常情况下,贪心算法的复杂度是O(n)本篇博客将运用这种思想来解决leetcode上316号问题 问题描述:Given a string which contains only lowercase letter

Quiteen的博客 578

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

[leetcode] 316. Remove Duplicate Letters 解题报告

题目链接: https://leetcode.com/problems/remove-duplicate-letters/ Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You mu

小榕流光的专栏 3174

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

leetcode 316. Remove Duplicate Letters

题意 给你一个由'a'到'z'的字符数组,求出一个不包含重复字符的 但是全部字符都要存在的 字典序最小的字符串 如 'bcaabc' 答案'abc' 题解 count记录当前字符x的出现次数 用一个栈来存结果 如果当前字符没在栈出现过,且当前字符小于栈顶的元素,且栈顶的元素 后面还出现,那么我们就pop,然后让当前字符加到栈中 class Solution { public: s...

YZ930035683的博客 226

【leetcode】316. Remove Duplicate Letters

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a...

ghscarecrow的博客 323

leetcode:316. Remove Duplicate Letters 题解

题目 Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical ord

iterate7的博客 2241

LeetCode String 316 Remove Duplicate Letters

316. Remove Duplicate Letters Given a string which contains only lowercase letters, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smal...

Yi Jiao's Blog 175

LeetCode 316: Remove Duplicate Letters

316. Remove Duplicate LettersDifficulty: Hard Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your re

Cycle1413的博客 446

leetcode :316 Remove Duplicate Letters : 贪心+递归搜索

316. Remove Duplicate Letters My Submissions Question Editorial Solution Total Accepted: 11048 Total Submissions: 44956 Difficulty: Hard Given a string which contains only lowerca

smileyk的专栏 1948

LeetCode //C - 316. Remove Duplicate Letters

【代码】LeetCode //C - 316. Remove Duplicate Letters。

Made in Code 1209
上一篇: LeetCode 264. Ugly Number II
下一篇: Angular 项目学习总结
Dale_zero
博客等级 码龄9年 10粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值