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:

  1. The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
Accepted
61,989
Submissions
183,954
 

class Solution {
public boolean validPalindrome(String s) {
int i = -1, j = s.length();
while(++i < --j) {
if(s.charAt(i) != s.charAt(j))
return isPalindrome(s,i+1,j) || isPalindrome(s,i,j-1);
}
return true;
}
private boolean isPalindrome(String s, int i, int j) {
while(i < j) {
if(s.charAt(i++) != s.charAt(j--)) return false;
}
return true;
}
}

680. Valid Palindrome II【Easy】【双指针-可以删除一个字符,判断是否能构成回文字符串】的更多相关文章

  1. 680. Valid Palindrome II【easy】

    680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Jud ...

  2. 【Leetcode_easy】680. Valid Palindrome II

    problem 680. Valid Palindrome II solution: 不理解判断函数中的节点的问题... class Solution { public: bool validPali ...

  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】680. Valid Palindrome II 验证回文字符串 Ⅱ(Python)

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

  5. Python 解LeetCode:680. Valid Palindrome II

    题目:给定一个字符串,在最多删除一个字符的情况下,判断这个字符串是不是回文字符串. 思路:回文字符串,第一想到的就是使用两个指针,前后各一个,当遇到前后字符不一致的时候,有两种情况,删除前面字符或者删 ...

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

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

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

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

  9. 【LeetCode】680. Valid Palindrome II

    Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/valid-palindrome ...

随机推荐

  1. rocketmq单机搭建

    RocketMQ 是alibaba开源的消息队列. 本文使用的是开源版本v3.18 系统: centos6.x最小化安装 需要用到的软件包: jdk-7u67-linux-x64.tar.gz ali ...

  2. redis启动脚本

    #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the ...

  3. jQuery日历签到插件

    插件比较简单,先来看DEMO吧,http://codepen.io/jonechen/pen/bZWdXq: CSS部分: *{margin:0;padding:0;font:14px/1.8 &qu ...

  4. Centos下Mysql密码忘记解决办法

    1.修改MySQL的登录设置: # vim /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 例如: [mysqld] datadir=/var/lib/m ...

  5. Eclipse Tomcat Project报错:HTTP Status 404错误

    想要在eclipse里部署tomcat,结果tomcat单独可以通过连接测试,用eclipse就404了 404肯定都是目录不对,试了半天在eclipse下改了一下配置和文件位置就行了 1.先在菜单栏 ...

  6. ORA-02291:parent key not found

    Hibernate operation: Could not execute JDBC batch update; SQL [insert into dchnpricecarchancesource ...

  7. Join vs merge vs lookup

    The obvious benefit of merge over join is the ability to add reject links. I can't upload pictures. ...

  8. JS中,children和childNodes的不同之处

    <ul id="ul"><li></li><li></li><li><span></spa ...

  9. C++之指针,引用与数组

    引用只是对象的另一个名字,通过在变量名前面添加"&”符号来定义,而指针保存的是另一个对象的地址,它们两都提供了间接访问所服务变量的途径. 但是它们的差别还是挺大的: 先从它们的值说起 ...

  10. SD 模拟sip 读写子程序

    void simulate_spi_write_byte(u8 data){ u8 kk; SPI3_CS(0); SPI3_SCK(0); delay_us(1); //???spi???1/2us ...