当前位置:网站首页>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;
}
}
}
边栏推荐
- 激动人心,2022开放原子全球开源峰会报名火热开启
- Leetcode 208. Implement trie (prefix tree)
- Dynamic programming -- linear DP
- FFT 学习笔记(自认为详细)
- 测试/开发程序员的成长路线,全局思考问题的问题......
- BiShe - College Student Association Management System Based on SSM
- 3D模型格式汇总
- How does Huawei enable debug and how to make an image port
- Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
- The population logic of the request to read product data on the sap Spartacus home page
猜你喜欢
ADS-NPU芯片架构设计的五大挑战
Cannot resolve symbol error
Mathematical modeling learning from scratch (2): Tools
DOM introduction
Cf:d. insert a progression [about the insert in the array + the nature of absolute value + greedy top-down]
Docker compose配置MySQL并实现远程连接
ubantu 查看cudnn和cuda的版本
激动人心,2022开放原子全球开源峰会报名火热开启
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
Exciting, 2022 open atom global open source summit registration is hot
随机推荐
Cf:d. insert a progression [about the insert in the array + the nature of absolute value + greedy top-down]
关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
Recursive method converts ordered array into binary search tree
yii中console方法调用,yii console定时任务
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
Leetcode 208. 实现 Trie (前缀树)
Study diary: February 13, 2022
IP storage and query in MySQL
File upload vulnerability test based on DVWA
网易智企逆势进场,游戏工业化有了新可能
Programmer growth Chapter 9: precautions in real projects
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
Tcpdump: monitor network traffic
Some features of ECMAScript
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
Modify the ssh server access port number
ADS-NPU芯片架构设计的五大挑战
What is the most suitable book for programmers to engage in open source?
SCM Chinese data distribution
FFT learning notes (I think it is detailed)