当前位置:网站首页>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;
}
}
}
边栏推荐
- 朝招金安全吗 会不会亏损本金
- 在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
- Paging of a scratch (page turning processing)
- BiShe - College Student Association Management System Based on SSM
- FFT learning notes (I think it is detailed)
- Idea sets the default line break for global newly created files
- The population logic of the request to read product data on the sap Spartacus home page
- 电气数据|IEEE118(含风能太阳能)
- VMware Tools installation error: unable to automatically install vsock driver
- [Arduino syntax - structure]
猜你喜欢
Daily practice - February 13, 2022
c#网页打开winform exe
037 PHP login, registration, message, personal Center Design
Xunrui CMS plug-in automatically collects fake original free plug-ins
Unity | 实现面部驱动的两种方式
The growth path of test / development programmers, the problem of thinking about the overall situation
The population logic of the request to read product data on the sap Spartacus home page
ADS-NPU芯片架构设计的五大挑战
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Exciting, 2022 open atom global open source summit registration is hot
随机推荐
Interview must brush algorithm top101 backtracking article top34
Recursive method to realize the insertion operation in binary search tree
Some features of ECMAScript
MySQL learning notes 2
FFT learning notes (I think it is detailed)
Threedposetracker project resolution
Spir - V premier aperçu
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
朝招金安全吗 会不会亏损本金
Yii console method call, Yii console scheduled task
Vulhub vulnerability recurrence 74_ Wordpress
File upload vulnerability test based on DVWA
leetcode刷题_反转字符串中的元音字母
3D模型格式汇总
A Cooperative Approach to Particle Swarm Optimization
leetcode刷题_平方数之和
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
Format code_ What does formatting code mean
[day 30] given an integer n, find the sum of its factors