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'.

思路:

代码:

 class Solution {
public boolean validPalindrome(String s) {
int l = 0;
int r = s.length()-1;
while(l < r){
if(s.charAt(l) != s.charAt(r)){
// try to delete a left side char || delete a right side char
return isPalin(s, l+1,r) || isPalin(s, l,r-1);
}else{
l++;
r--;
}
}
return true; } // helper function to judge valid palindrome
private boolean isPalin(String s , int l, int r){
while(l < r){
if(s.charAt(l++)!=s.charAt(r--)) return false;
}
return true;
}
}

[leetcode]680. Valid Palindrome II有效回文II(可至多删一原字符)的更多相关文章

  1. 【LeetCode】- Valid Palindrome(右回文)

    [ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...

  2. LeetCode 125 Valid Palindrome(有效回文)(*)

    翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...

  3. [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 ...

  4. [LeetCode] 409. Longest Palindrome 最长回文

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

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

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

  6. leetcode题解:Valid Palindrome(判断回文)

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  7. LeetCode 680. Valid Palindrome II(双指针)

    题意:给定一个字符串,可以最多去掉一个字符,判断是否可以使该字符串成为一个回文串. 分析:head和tail双指针分别指向字符串首尾,如果s[head] != s[tail],则要么去掉s[head] ...

  8. 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字

    我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...

  9. 从0开始的LeetCode生活—9. Palindrome Number(回文数)

    题目大意: 判断输入的数字是不是回文数.所谓回文数就是正反读都一样的数字,比如说11,121,1221这样子的数字.负数不会是回文数. 解题思路: 思路一:如果这个数是负数,则返回false,否则用一 ...

随机推荐

  1. 关于rawurldecode PHP自动解码

    发表于: 2007-12-05 12:16:20   在网上找到资料说通过javascript传递参数时如果用了encodeURIComponent函数对参数进行编码,在PHP里面需要用 rawurl ...

  2. CentOS7 安装supervisor守护进程管理器

    supervisor没有发布在标准的CentOS源在,需要安装epel源.这种方式安装的可能不是最新版本,但比较方便,安装完成之后,配置文件会自动帮你生成. 默认配置文件:/etc/superviso ...

  3. win 关闭正在使用的端口

    1.Windows平台 在windows命令行窗口下执行: 1.查看所有的端口占用情况 C:\>netstat -ano 2.查看指定端口的占用情况 C:\>netstat -aon|fi ...

  4. 提高solr的搜索速度

    之前是使用12台机分布式搜索,1台为主机做索引并分发给子机,8台做大索引搜索服务,3 台做小索引搜索服务,配置基本是内存在4-8G,cpu:2-8core的服务器,索引的大小为8G.搜索的响应时间 是 ...

  5. python之路05

    一  元组 对于元组我们可以把他看成一个不可变的列表# 元组:在()内用逗号分隔开的能够存多个值,对于元组来说列表有的一些功能它基本上都有,# 1.按索引取值(正向取+反向取):只能取# 2.切片(顾 ...

  6. java在注解中绑定方法参数的解决方案

    我们有这样子的需求,需要记录用户操作某个方法的信息并记录到日志里面,例如,用户在保存和更新任务的时候,我们需要记录下用户的ip,具体是保存还是更新,调用的是哪个方法,保存和更新的任务名称以及操作是否成 ...

  7. [Delphi] 快速获取文件大小

    function GetFileSize(const fName: AnsiString): Int64; var hFile: THandle; begin hFile := _lopen(PAns ...

  8. HAproxy使用

    参考官网 安装HAproxy/ pull 官方镜像 本地安装:本地安装路径:/usr/local/haproxy/配置: 添加:/usr/local/haproxy/conf/haproxy.cfg添 ...

  9. zabbix监控系统日志

    监控日志必须让agent运行在主动模式 参考网站:https://www.cnblogs.com/dadonggg/p/8611054.html?from=singlemessage

  10. 35. oracle中instr在平台上的转换用法

    //INSTR('15,17,29,3,30,4',a.femployee) var instrSql = fun.funHelper.charIndex('a.femployee',"'& ...