当前位置:网站首页>Leetcode 1209. Delete all adjacent duplicates II in the string
Leetcode 1209. Delete all adjacent duplicates II in the string
2022-06-23 11:47:00 【I'm not xiaohaiwa~~~~】

Give you a string s,「k Double duplicate deletion 」 Will be from s Choose from k Two adjacent and equal letters , And delete them , Connect the left and right sides of the deleted string .
You need to s Repeat the deletion operation for an unlimited number of times , Until it can't continue .
After performing all deletion operations , Returns the resulting string .
The answer to this question is guaranteed to be unique .
Example 1:
Input :s = "abcd", k = 2
Output :"abcd"
explain : There is nothing to delete .
Example 2:
Input :s = "deeedbbcccbdaa", k = 3
Output :"aa"
explain :
Delete first "eee" and "ccc", obtain "ddbbbdaa"
And then delete "bbb", obtain "dddaa"
Finally delete "ddd", obtain "aa"
Example 3:
Input :s = "pbbcggttciiippooaais", k = 2
Output :"ps"
Tips :
- 1 <= s.length <= 10^5
- 2 <= k <= 10^4
- s There are only lowercase letters in .
Code:
class Solution {
public:
string removeDuplicates(string s, int k) {
string res;
int size=s.length();
int num=0;
for(int i=0;i<size;i++)
{
if(res.back()!=s[i])
{
res.push_back(s[i]);
num=1;
continue;
}
else
{
num++;
res.push_back(s[i]);
if(num==k)
{
for(int j=0;j<k;j++)
{
res.pop_back();
}
num=1;
for(int j=res.size()-1;j>=0;j--)
{
if((j-1)>=0)
{
if(res[j]==res[j-1])
num++;
else
break;
}
}
}
}
}
return res;
}
};
边栏推荐
- Mobile securities account opening transaction? Is it safe to open an account online now?
- 5 个关于 NFT 的技术漏洞
- 你真的理解LDO的輸出電容嗎!?
- 网上注册股票开户很困难么?现在网上开户安全么?
- Video data annotation tools and platforms (data annotation company)
- @黑马粉丝,这份「高温补贴」你还没领?
- 在flinksql中 kafka流表跟mysql 纬度流表做left join,根据I’d做关联,假
- 64路电话+2路千兆以太网64路PCM电话光端机语音电话转光纤
- Oversampling Series III: quantization error and oversampling rate
- 想学习eTS开发?教你开发一款IQ-EQ测试应用
猜你喜欢

【零基础微信小程序】基于百度大脑人像分割的证件照换底色小程序实战开发

16路HD-SDI光端机多路HD-SDI高清视频光端机16路3G-SDI高清音视频光端机

直播带货app源码搭建中,直播CDN的原理是什么?

32路电话+2路千兆以太网32路PCM电话光端机支持FXO口FXS语音电话转光纤

【云原生&微服务八】Ribbon负载均衡策略之WeightedResponseTimeRule源码剖析(响应时间加权)

Redis 入门-第一篇-数据结构与对象-简单动态字符串(SDS)

成熟的知识管理,应具备哪些条件?

使用Mycat进行MySQL单库分表

Vone news | wanglian technology empowers the public to enjoy the self-organization management of the chain network, creating an enterprise level alliance Dao
![Openharmony application development [01]](/img/b1/1e37cecd3d3f9e46444c202cfb1b99.png)
Openharmony application development [01]
随机推荐
股票网上开户及开户流程怎样?手机开户安全么?
成熟的知识管理,应具备哪些条件?
quarkus+saas多租户动态数据源切换实现简单完美
电容参数哪里找!?
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
On the structure of annotation platform
Deep analysis and Simulation of list
mysql,如何在使用存储过程计算最大值
Learning notes sweep crawler framework
Groovy之范围
Oversampling Series II: Fourier transform and signal-to-noise ratio
MySQL matches multiple values in one field
1路百兆光纤收发器1百兆光1百兆电桌面式以太网光纤收发器内置电源
股权转让热点:重庆建科建设工程质量检测有限公司93.75%股权转让
How does easygbs solve the abnormal use of intercom function?
Which securities company is the most reliable and safe to open an account
互联网奇迹-小米究竟是怎么盈利
navicat定时任务无效
DevEco Device Tool 助力OpenHarmony设备开发
切比雪夫不等式证明及应用