当前位置:网站首页>leetcode刷题_验证回文字符串 Ⅱ
leetcode刷题_验证回文字符串 Ⅱ
2022-07-06 01:19:00 【身影王座】
题目描述

Java解决方法
class Solution {
public boolean Palindrome(String s, int start, int end)
{
while(start < end)
{
if(s.charAt(start) == s.charAt(end))
{
start++;
end--;
}
else
{
return false;
}
}
return true;
}
public boolean validPalindrome(String s) {
int start = 0;
int end = s.length() - 1;
while(start < end)
{
if(s.charAt(start) == s.charAt(end))
{
start++;
end--;
}
else
{
break;
}
}
if(start >= end)
{
return true;
}
else
{
boolean valid1 = Palindrome(s, start + 1, end);
boolean valid2 = Palindrome(s, start, end - 1);
if(valid1 || valid2)
{
return true;
}
else
{
return false;
}
}
}
}
C解决方法
bool Palindrome(char * s, int start, int end)
{
while(start < end)
{
if(s[start] == s[end])
{
start++;
end--;
}
else
{
return false;
}
}
return true;
}
bool validPalindrome(char * s){
bool valid1;
bool valid2;
int start = 0;
int end = strlen(s) - 1;
while(start < end)
{
if(s[start] == s[end])
{
start++;
end--;
}
else
{
break;
}
}
if(start >= end)
{
return true;
}
else
{
valid1 = Palindrome(s, start + 1, end);
valid2 = Palindrome(s, start, end - 1);
if(valid1 || valid2)
{
return true;
}
else
{
return false;
}
}
}
边栏推荐
- Idea sets the default line break for global newly created files
- BiShe - College Student Association Management System Based on SSM
- 记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
- Mysql--- query the top 5 students
- 2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
- Questions about database: (5) query the barcode, location and reader number of each book in the inventory table
- 网易智企逆势进场,游戏工业化有了新可能
- Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
- 毕设-基于SSM高校学生社团管理系统
- MATLB | real time opportunity constrained decision making and its application in power system
猜你喜欢

Recoverable fuse characteristic test

Cf:c. the third problem

MATLB|实时机会约束决策及其在电力系统中的应用

电气数据|IEEE118(含风能太阳能)

Dede collection plug-in free collection release push plug-in

037 PHP login, registration, message, personal Center Design

Ordinary people end up in Global trade, and a new round of structural opportunities emerge

View class diagram in idea

VMware Tools安装报错:无法自动安装VSock驱动程序
![Cf:h. maximum and [bit operation practice + K operations + maximum and]](/img/c2/9e58f18eec2ff92e164d8d156629cf.png)
Cf:h. maximum and [bit operation practice + K operations + maximum and]
随机推荐
What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
Huawei Hrbrid interface and VLAN division based on IP
ADS-NPU芯片架构设计的五大挑战
China Taiwan strategy - Chapter 8: digital marketing assisted by China Taiwan
Ubantu check cudnn and CUDA versions
Study diary: February 13, 2022
Recommended areas - ways to explore users' future interests
3D模型格式汇总
Introduction to robotics I. spatial transformation (1) posture, transformation
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
282. Stone consolidation (interval DP)
The population logic of the request to read product data on the sap Spartacus home page
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
Dynamic programming -- linear DP
Code Review关注点
GNSS terminology
In the era of industrial Internet, we will achieve enough development by relying on large industrial categories
WordPress collection plug-in automatically collects fake original free plug-ins
False breakthroughs in the trend of London Silver