[leetcode] 5. Longest Palindromic Substring
791
2022-08-22
[leetcode] 680. Valid Palindrome II
Description
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.
Example 1: Input:
"aba"
Output:
True
Example 2: Input:
"abca"
Output:
True
Explanation:
You could delete the character 'c'.
Note:
The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
分析
题目的意思是:给定一个字符串,然后可以删除一个字符,使其变成回文子串。
这个题目是典型的递归判断的题目,设定left从前往后遍历,right从后往前遍历,如果s[left]!=s[right]则判断s的left+1~right或者left ~ right-1是否是回文子串就行了哈。
代码
class Solution {public: bool validPalindrome(string s) { int left=0; int right=s.length()-1; while(left 参考文献 [LeetCode Valid] Palindrome II 验证回文字符串之二
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~