当前位置:网站首页>Sword finger offer II 019 Delete at most one character to get palindrome (simple)
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
2022-04-23 14:40:00 【Heavy garbage】
Ideas : Double pointer , Reduce the complexity to O(n)
Specific ideas :l=0 r=n-1 If s[l]==s[r] be l++;r–; Otherwise, as long as s[l+1,r] perhaps s[l,r-1] It's palindrome
class Solution {
public:
bool valid(const string &s, int l, int r) {
while (l < r) {
if (s[l] != s[r]) return false;
l++;r--;
}
return true;
}
bool validPalindrome(string s) {
int l =0, r = s.size() - 1;
while (l < r) {
if (s[l] == s[r]) {
l++;
r--;
}else {
return valid(s, l + 1, r) || valid(s, l, r - 1);
}
}
return true;
}
};
版权声明
本文为[Heavy garbage]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231435304495.html
边栏推荐
- 矩阵交换行列
- MySQL报错packet out of order
- C语言p2选择分支语句详解
- [detailed explanation of factory mode] factory method mode
- Unity_代码方式添加绑定按钮点击事件
- capacitance
- Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
- ASEMI三相整流桥和单相整流桥的详细对比
- AT89C52单片机的频率计(1HZ~20MHZ)设计,LCD1602显示,含仿真、原理图、PCB与代码等
- Chapter 7 of JVM series -- bytecode execution engine
猜你喜欢
555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
【工厂模式详解】工厂方法模式
qt之.pro文件详解
全连接层的作用是什么?
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
详解TCP的三次握手
51单片机的直流电机PWM调速控制系统(附Proteus仿真+C程序等全套资料)
A blog allows you to learn how to write markdown on vscode
随机推荐
QT actual combat: Yunxi chat room
Qt实战:云曦日历篇
C语言知识点精细详解——数据类型和变量【1】——进位计数制
【工厂模式详解】工厂方法模式
[servlet] detailed explanation of servlet (use + principle)
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
UML project example -- UML diagram description of tiktok
Qt实战:云曦聊天室篇
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
8.2 文本预处理
async void 导致程序崩溃
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
2-Go变量操作
Some little records~
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
数组模拟队列进阶版本——环形队列(真正意义上的排队)
【无标题】