316 Remove Duplicate Letters 去除重复字母
给定一个仅包含小写字母的字符串,去除重复的字母使得所有字母出现且仅出现一次。你必须保证返回结果是所有可能结果中的以字典排序的最短结果。
例如:
给定 "bcabc"
返回 "abc"
给定 "cbacdcbc"
返回 "acdb"
详见:https://leetcode.com/problems/remove-duplicate-letters/description/
C++:
class Solution {
public:
string removeDuplicateLetters(string s) {
int m[256]={0},visited[256]={0};
string res="0";
for(char a:s)
{
++m[a];
}
for(char a:s)
{
--m[a];
if(visited[a])
{
continue;
}
while(a<res.back()&&m[res.back()])
{
visited[res.back()]=0;
res.pop_back();
}
res+=a;
visited[a]=1;
}
return res.substr(1);
}
};
详见:http://www.cnblogs.com/grandyang/p/5085379.html
316 Remove Duplicate Letters 去除重复字母的更多相关文章
- 贪心:leetcode 870. Advantage Shuffle、134. Gas Station、452. Minimum Number of Arrows to Burst Balloons、316. Remove Duplicate Letters
870. Advantage Shuffle 思路:A数组的最大值大于B的最大值,就拿这个A跟B比较:如果不大于,就拿最小值跟B比较 A可以改变顺序,但B的顺序不能改变,只能通过容器来获得由大到小的顺 ...
- [LeetCode] 316. Remove Duplicate Letters 移除重复字母
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- 316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- leetcode 316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- 【LeetCode】316. Remove Duplicate Letters 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- leetcode@ [316] Remove Duplicate Letters (Stack & Greedy)
https://leetcode.com/problems/remove-duplicate-letters/ Given a string which contains only lowercase ...
- 316. Remove Duplicate Letters (accumulate -> count of the difference elements in a vector)
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- 【leetcode】316. Remove Duplicate Letters
题目如下: Given a string which contains only lowercase letters, remove duplicate letters so that every l ...
- Remove Duplicate Letters
316. Remove Duplicate Letters Total Accepted: 2367 Total Submissions: 12388 Difficulty: Medium Given ...
随机推荐
- DataFrame NaN 替换为零
一个DataFrame 其中有空值NaN,将其替换为0: df.fillna(0) 如果将第一列替换为0: df[1].fillna(0,inplace=True)
- Codeforces 263A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input ...
- [luoguP2158] [SDOI2008]仪仗队(数论)
传送门 可以看出 (i, j) 能被看到,(i * k, j * k) 都会被挡住 暴力 所以 gcd(i, j) == 1 的话 ans ++ 那么可以枚举一半(中轴对称),求解答案,只能拿30分 ...
- [luoguP2387] 魔法森林(LCT + 并查集)
传送门 并查集真是一个判断连通的好东西! 连通性用并查集来搞. 把每一条边按照 a 为关键字从小到大排序. 那么直接枚举,动态维护 b 的最小生成树 用 a[i] + 1 ~ n 路径上最大的 b[i ...
- cpus Vs cpu period and cpu quota
1. https://docs.oracle.com/cd/E37670_01/E75728/html/section-zb1_wqw_gt.html To control a container' ...
- Hackerrank alien-flowers(数学公式)
题意:求能够构造出的符合以下条件的字符串的数目 .字符串只由R和B组成且长度不为0 .字符串含有A个RR,B个RB,C个BB,D个BR A,B,C,D<=1e5 分析:最简单的方法就是dp,但是 ...
- MySQL主从复制邮件报警脚本
#!/bin/shexport PATH=$PATH:/application/mysql/3306/binlogFile=`date +"%Y-%m-%d %H:%M:%S"`_ ...
- 基本的数据类型分析----java.lang.Number类及其子类分析
本文转自http://blog.csdn.net/springcsc1982/article/details/8788345 感谢作者 编写了一个测试程序,如下: int a = 1000, b= 1 ...
- jquery-mobile 学习笔记之二(表单创建)
绪上 一.注意事项 1. <form> 元素必须设置 method 和 action 属性 2. 每一个表单元素必须设置唯一的 "id" 属性. 该 id 在网站的页面 ...
- git项目创建
1.在gitserver上创建git项目如图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill ...