当前位置:网站首页>Leetcode skimming questions_ Verify palindrome string II
Leetcode skimming questions_ Verify palindrome string II
2022-07-06 01:24:00 【Figure throne】
Title Description
Java resolvent
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 resolvent
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;
}
}
}
边栏推荐
- SPIR-V初窺
- XSS learning XSS lab problem solution
- internship:项目代码所涉及陌生注解及其作用
- ThreeDPoseTracker项目解析
- WordPress collection plug-in automatically collects fake original free plug-ins
- 【全網最全】 |MySQL EXPLAIN 完全解讀
- Leetcode1961. Check whether the string is an array prefix
- Huawei Hrbrid interface and VLAN division based on IP
- Recommended areas - ways to explore users' future interests
- 3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
猜你喜欢
Threedposetracker project resolution
Dede collection plug-in free collection release push plug-in
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
Kotlin basics 1
WordPress collection plug-in automatically collects fake original free plug-ins
A picture to understand! Why did the school teach you coding but still not
Vulhub vulnerability recurrence 75_ XStream
MATLB | real time opportunity constrained decision making and its application in power system
Yii console method call, Yii console scheduled task
c#网页打开winform exe
随机推荐
DOM introduction
Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range
General operation method of spot Silver
Interview must brush algorithm top101 backtracking article top34
Unity | 实现面部驱动的两种方式
Modify the ssh server access port number
False breakthroughs in the trend of London Silver
A picture to understand! Why did the school teach you coding but still not
GNSS terminology
Leetcode 208. 实现 Trie (前缀树)
Opinions on softmax function
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
视频直播源码,实现本地存储搜索历史记录
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
Live broadcast system code, custom soft keyboard style: three kinds of switching: letters, numbers and punctuation
3D模型格式汇总
【第30天】给定一个整数 n ,求它的因数之和
Superfluid_ HQ hacked analysis
The population logic of the request to read product data on the sap Spartacus home page
MUX VLAN configuration