当前位置:网站首页>Leetcode316- remove duplicate letters - stack - greedy - string
Leetcode316- remove duplicate letters - stack - greedy - string
2022-07-01 04:53:00 【Li Fan, hurry up】
Note:
Maintain an answer string , Traverse the given string , Judge the current character each time , Is it smaller than the end of the answer string , If it's small , Let's see if the last one can be deleted , Delete if you can , You can't delete it. There's no way , Just keep it
The code is as follows :
class Solution {
public:
string removeDuplicateLetters(string s) {
string stk;
unordered_map<char, bool> ins;
unordered_map<char, int> last;
for(int i = 0; i < s.size(); i ++) last[s[i]] = i;
for(int i = 0; i < s.size(); i ++){
if(ins[s[i]]) continue;
while(stk.size() && stk.back() > s[i] && last[stk.back()] > i){
ins[stk.back()] = false;
stk.pop_back();
}
ins[s[i]] = true;
stk += s[i];
}
return stk;
}
};
边栏推荐
- Pytest automated testing - compare robotframework framework
- pytorch 卷积操作
- 解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
- 先有网络模型的使用及修改
- 数据加载及预处理
- 线程类的几大创建方法
- 【暑期每日一题】洛谷 P3742 umi的函数
- Matters behind the construction of paint testing laboratory
- Leecode question brushing record 1332 delete palindrome subsequence
- Pytoch (IV) -- visual tool visdom
猜你喜欢

Common methods in transforms

Openresty rewrites the location of 302

Pytorch(四) —— 可视化工具 Visdom

Fitness without equipment

神经网络-最大池化的使用

Pytorch(一) —— 基本语法
![[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply](/img/c2/6dfb9f477306edb46ff2a6a6ca32dd.png)
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply

Pytorch(三) —— 函数优化

PR 2021 quick start tutorial, learn about the and functions of the timeline panel

Distributed architecture system splitting principles, requirements and microservice splitting steps
随机推荐
AssertionError assert I.ndim == 4 and I.shape[1] == 3
pytorch中常用数据集的使用方法
洗个冷水澡吧
神经网络-非线性激活
LeetCode_ 66 (plus one)
解决qiankun中子应用外链文件无法获取
Oracle views the creation time of the tablespace in the database
Basic usage, principle and details of session
缓冲流与转换流
Pytorch(三) —— 函数优化
Leecode records the number of good segmentation of 1525 strings
Pytorch(二) —— 激活函数、损失函数及其梯度
[daily question in summer] Luogu p2026 find the analytic formula of primary function
Some tools that research dogs may need
js解决浮点数相乘精度丢失问题
C -- array
CF1638E. Colorful operations Kodori tree + differential tree array
【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
最长递增子序列及最优解、动物总重量问题
科研狗可能需要的一些工具
