给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。

示例 1:

输入: "aba" 输出: True

示例 2:

输入: "abca" 输出: True 解释: 你可以删除c字符。

注意:

  1. 字符串只包含从 a-z 的小写字母。字符串的最大长度是50000。
class Solution {
public:
bool validPalindrome(string s) {
int len = s.size();
if(len == 0)
return true;
for(int i = 0; i < len / 2; i++)
{
if(s[i] != s[len - 1 - i])
{
string temp1 = s;
string temp2 = s;
temp1.erase(i, 1);
temp2.erase(len - 1 - i, 1);
return ReCheck(temp1) || ReCheck(temp2);
}
}
return true;
} bool ReCheck(string str)
{
int len = str.size();
if(len == 0)
return true;
for(int i = 0; i < len / 2; i++)
{
if(str[i] != str[len - 1 - i])
{
return false;
}
}
return true;
}
};

Leetcode680.Valid Palindrome II验证回文字符串2的更多相关文章

  1. [LeetCode] 680. Valid Palindrome II 验证回文字符串 II

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  2. 【LeetCode】680. Valid Palindrome II 验证回文字符串 Ⅱ(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 思路来源 初版方案 进阶方案 日期 题目地址 ...

  3. [LeetCode] Valid Palindrome II 验证回文字符串之二

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  4. LeetCode 680. Valid Palindrome II (验证回文字符串 Ⅱ)

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  5. LeetCode OJ:Valid Palindrome(验证回文)

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  6. [leetcode]680. Valid Palindrome II有效回文II(可至多删一原字符)

    Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...

  7. LeetCode 680. 验证回文字符串 Ⅱ(Valid Palindrome II) 1

    680. 验证回文字符串 Ⅱ 680. Valid Palindrome II 题目描述 给定一个非空字符串 s,最多删除一个字符.判断是否能成为回文字符串. 每日一算法2019/5/4Day 1Le ...

  8. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  9. [LeetCode] 125. Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

随机推荐

  1. base64,AES,RSA,SHA和MD5等加密方式(jdk)

    import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import javax.crypto.Cipher; import jav ...

  2. Windows API 第16篇 GetLogicalDrivers 获取驱动器位掩码

    函数原型:DWORD GetLogicalDrives(VOID);The GetLogicalDrives function retrieves a bitmask representing the ...

  3. Spring_注解形式的配置

    1.spring配置: 扫描被下面的注解所注解的类, 把这些类直接配置为bean. 例如: @Controller @Service @Repository @Component 这四个注解 Cont ...

  4. element-ui 使用笔记

    1,获取级联选择器 cascader的值 获取value值:就是v-model绑定的值, 获取label值:要先给cascader组件一个ref值,然后通过 this.$refs.组件的ref值.cu ...

  5. javascript的Touch事件

    js的touch事件,一般用于移动端的触屏滑动 $(function(){document.addEventListener("touchmove", _touch, false) ...

  6. 关于自定义 UITableViewCell

    自定义UITableViewCell的方法有很多 发现一些人都会遇到自己定义的cell里面图片错乱的问题 这个问题往往是因为没有实现prepareForReuse这个方法导致的. UITableVie ...

  7. WPF DataGrid动态生成列的单元格背景色绑定

    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Column.DisplayInde ...

  8. 在线模拟http-post请求

    今天,要测试一个post请求的API,找了下,下面的网站可以直接利用起来,mark下 http://www.atool.org/httptest.php

  9. sudo 授权许可使用的su,也是受限制的su

    sudo 的适用条件: 由于su 对切换到超级权限用户root后,权限的无限制性,所以su并不能担任多个管理员所管理的系统.如果用su 来切换到超级用户来管理系统,也不能明确哪些工作是由哪个管理员进行 ...

  10. 字符串匹配算法之kmp算法

    kmp算法是一种效率非常高的字符串匹配算法,是由Knuth,Morris,Pratt共同提出的模式匹配算法,所以简称KMP算法 算法思想 在一个字符串中查找另一个字符串时,会遇到如下图的情况 我们通常 ...