当前位置:网站首页>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;
}
}
}
边栏推荐
- CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
- Cglib dynamic agent -- example / principle
- What is the most suitable book for programmers to engage in open source?
- Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
- Is chaozhaojin safe? Will it lose its principal
- Recursive method to realize the insertion operation in binary search tree
- A glimpse of spir-v
- 2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
- 朝招金安全吗 会不会亏损本金
- Cf:c. the third problem
猜你喜欢
Recoverable fuse characteristic test
Four commonly used techniques for anti aliasing
Exciting, 2022 open atom global open source summit registration is hot
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
95后CV工程师晒出工资单,狠补了这个,真香...
The inconsistency between the versions of dynamic library and static library will lead to bugs
JVM_ 15_ Concepts related to garbage collection
测试/开发程序员的成长路线,全局思考问题的问题......
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
MySQL learning notes 2
随机推荐
Study diary: February 13, 2022
JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
VMware Tools installation error: unable to automatically install vsock driver
Opinions on softmax function
DOM introduction
Basic process and testing idea of interface automation
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
Construction plan of Zhuhai food physical and chemical testing laboratory
Live video source code, realize local storage of search history
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
【第30天】给定一个整数 n ,求它的因数之和
A glimpse of spir-v
Zhuhai laboratory ventilation system construction and installation instructions
毕设-基于SSM高校学生社团管理系统
GNSS terminology
cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
JVM_ 15_ Concepts related to garbage collection
Modify the ssh server access port number
Obstacle detection
Building core knowledge points