当前位置:网站首页>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;
}
}
}
边栏推荐
- GNSS terminology
- cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
- SPIR-V初窥
- Unity | two ways to realize facial drive
- Kotlin core programming - algebraic data types and pattern matching (3)
- WGet: command line download tool
- 2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
- Finding the nearest common ancestor of binary tree by recursion
- 3D模型格式汇总
- 基於DVWA的文件上傳漏洞測試
猜你喜欢

Huawei Hrbrid interface and VLAN division based on IP

Test de vulnérabilité de téléchargement de fichiers basé sur dvwa

VMware Tools安装报错:无法自动安装VSock驱动程序

IP storage and query in MySQL

servlet(1)

WordPress collection plug-in automatically collects fake original free plug-ins

DOM introduction

Building core knowledge points

Mathematical modeling learning from scratch (2): Tools

程序员搞开源,读什么书最合适?
随机推荐
Redis' cache penetration, cache breakdown, cache avalanche
Interview must brush algorithm top101 backtracking article top34
cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
The population logic of the request to read product data on the sap Spartacus home page
Fibonacci number
ubantu 查看cudnn和cuda的版本
Electrical data | IEEE118 (including wind and solar energy)
Zhuhai's waste gas treatment scheme was exposed
Recursive method converts ordered array into binary search tree
Building core knowledge points
【第30天】给定一个整数 n ,求它的因数之和
Four commonly used techniques for anti aliasing
FFT 学习笔记(自认为详细)
General operation method of spot Silver
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
Vulhub vulnerability recurrence 74_ Wordpress
Mysql--- query the top 5 students
How to see the K-line chart of gold price trend?
Recoverable fuse characteristic test
Finding the nearest common ancestor of binary search tree by recursion