当前位置:网站首页>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;
}
}
}
边栏推荐
- JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
- 关于softmax函数的见解
- Idea sets the default line break for global newly created files
- Leetcode1961. Check whether the string is an array prefix
- Study diary: February 13, 2022
- 在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
- 基于DVWA的文件上传漏洞测试
- Live video source code, realize local storage of search history
- 1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
- Development trend of Ali Taobao fine sorting model
猜你喜欢
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
Unity | 实现面部驱动的两种方式
激动人心,2022开放原子全球开源峰会报名火热开启
SSH login is stuck and disconnected
vSphere实现虚拟机迁移
View class diagram in idea
Dedecms plug-in free SEO plug-in summary
yii中console方法调用,yii console定时任务
Yii console method call, Yii console scheduled task
Recoverable fuse characteristic test
随机推荐
Four commonly used techniques for anti aliasing
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
Leetcode study - day 35
Unity | two ways to realize facial drive
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
Recommended areas - ways to explore users' future interests
Code Review关注点
现货白银的一般操作方法
Idea sets the default line break for global newly created files
How does Huawei enable debug and how to make an image port
JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
Spir - V premier aperçu
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
毕设-基于SSM高校学生社团管理系统
Logstash clear sincedb_ Path upload records and retransmit log data
File upload vulnerability test based on DVWA
Leetcode1961. Check whether the string is an array prefix
Fibonacci number
激动人心,2022开放原子全球开源峰会报名火热开启