当前位置:网站首页>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;
}
}
}
边栏推荐
- CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
- JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
- Daily practice - February 13, 2022
- Leetcode 208. 实现 Trie (前缀树)
- ctf. Show PHP feature (89~110)
- Overview of Zhuhai purification laboratory construction details
- Interview must brush algorithm top101 backtracking article top34
- 网易智企逆势进场,游戏工业化有了新可能
- 现货白银的一般操作方法
- [Arduino syntax - structure]
猜你喜欢
Dede collection plug-in free collection release push plug-in
General operation method of spot Silver
现货白银的一般操作方法
How to extract MP3 audio from MP4 video files?
Leetcode study - day 35
A Cooperative Approach to Particle Swarm Optimization
Yii console method call, Yii console scheduled task
False breakthroughs in the trend of London Silver
The inconsistency between the versions of dynamic library and static library will lead to bugs
ORA-00030
随机推荐
基於DVWA的文件上傳漏洞測試
Obstacle detection
What is the most suitable book for programmers to engage in open source?
JVM_ 15_ Concepts related to garbage collection
Nmap: network detection tool and security / port scanner
Mysql--- query the top 5 students
ctf. Show PHP feature (89~110)
Leetcode 剑指 Offer 59 - II. 队列的最大值
Live video source code, realize local storage of search history
Leetcode1961. Check whether the string is an array prefix
Leetcode daily question solution: 1189 Maximum number of "balloons"
How to extract MP3 audio from MP4 video files?
现货白银的一般操作方法
Is chaozhaojin safe? Will it lose its principal
ORA-00030
视频直播源码,实现本地存储搜索历史记录
SCM Chinese data distribution
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
Xunrui CMS plug-in automatically collects fake original free plug-ins
Recoverable fuse characteristic test