当前位置:网站首页>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;
}
}
}
边栏推荐
- Leetcode 208. Implement trie (prefix tree)
- 朝招金安全吗 会不会亏损本金
- 基於DVWA的文件上傳漏洞測試
- 3D model format summary
- FFT 学习笔记(自认为详细)
- servlet(1)
- What is the most suitable book for programmers to engage in open source?
- Some features of ECMAScript
- The inconsistency between the versions of dynamic library and static library will lead to bugs
- Leetcode daily question solution: 1189 Maximum number of "balloons"
猜你喜欢

程序员搞开源,读什么书最合适?

Daily practice - February 13, 2022

基於DVWA的文件上傳漏洞測試

Hcip---ipv6 experiment

cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】

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

Vulhub vulnerability recurrence 75_ XStream

SSH login is stuck and disconnected

How to see the K-line chart of gold price trend?

Building core knowledge points
随机推荐
现货白银的一般操作方法
cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
面试必刷算法TOP101之回溯篇 TOP34
Leetcode 208. Implement trie (prefix tree)
程序员成长第九篇:真实项目中的注意事项
Study diary: February 13, 2022
Five challenges of ads-npu chip architecture design
Recursive method converts ordered array into binary search tree
Daily practice - February 13, 2022
Tcpdump: monitor network traffic
Logstash clear sincedb_ Path upload records and retransmit log data
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
DOM introduction
Zhuhai's waste gas treatment scheme was exposed
How to see the K-line chart of gold price trend?
Leetcode study - day 35
Nmap: network detection tool and security / port scanner
伦敦银走势中的假突破
有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀
golang mqtt/stomp/nats/amqp