[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 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(可至多删一原字符)的更多相关文章
- 【LeetCode】- Valid Palindrome(右回文)
[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...
- LeetCode 125 Valid Palindrome(有效回文)(*)
翻译 给定一个字符串.确定它是否是回文的,仅仅考虑当中的数字和字符并忽略其它. 比如. "A man, a plan, a canal: Panama" 是回文的. "r ...
- [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 ...
- [LeetCode] 409. Longest Palindrome 最长回文
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- LeetCode OJ:Valid Palindrome(验证回文)
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- leetcode题解:Valid Palindrome(判断回文)
题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...
- LeetCode 680. Valid Palindrome II(双指针)
题意:给定一个字符串,可以最多去掉一个字符,判断是否可以使该字符串成为一个回文串. 分析:head和tail双指针分别指向字符串首尾,如果s[head] != s[tail],则要么去掉s[head] ...
- 《LeetBook》leetcode题解(9):Palindrome Number[E]——回文数字
我现在在做一个叫<leetbook>的开源书项目,把解题思路都同步更新到github上了,需要的同学可以去看看 地址:https://github.com/hk029/leetcode 这 ...
- 从0开始的LeetCode生活—9. Palindrome Number(回文数)
题目大意: 判断输入的数字是不是回文数.所谓回文数就是正反读都一样的数字,比如说11,121,1221这样子的数字.负数不会是回文数. 解题思路: 思路一:如果这个数是负数,则返回false,否则用一 ...
随机推荐
- windows,linux下SVN实现自动更新WEB目录
通过SVN进行版本库管理,每次提交后,都要在SVN服务器更新最新上传的版本到WEB目录进行同步.操作比较烦琐,而且效率也低.使用SVN钩子脚本进行WEB目录同步,可很好的解决这方面的问题.由于测试机器 ...
- 关于博主noble_
大家好啊,我是博主noble_,大家叫我noble就行了.我身处上海某初高中连体的市重点,校内OI比较弱. 个人常用OJ是洛谷,BZOJ,POJ,HDU,UVA.名字都叫noble_. 目前noble ...
- 【POJ】2480 Longge's problem(欧拉函数)
题目 传送门:QWQ 分析 题意就是求∑gcd(i, N) 1<=i <=N.. 显然$ gcd(i,n) = x $时,必然$x|n$. 所以我们枚举一下n的约数,对于每个约数x,显然$ ...
- PCIe Max_Payload_Size 和 Max_Read_Request_Size
最近PCIe在SSDFans上镜率挺高,那我们来聊两句MAX_READ_REQUEST_SIZE 和MAX_PAYLOAD_SIZE. 这两个东西都在PCIe Capability Structure ...
- Bogart BogartAutoCode.vb
Imports System.Data.SqlClient Imports System.Data Public Class BogartAutoCodeDataBase Private Conn A ...
- leetcode349
public class Solution { public int[] Intersection(int[] nums1, int[] nums2) { var list1 = nums1.ToLi ...
- 在spring中实现quartz的动态调度(开始、暂停、停止等)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/fantasic_van/article/details/74942062 需求: 需要在页面设定某个 ...
- Simple2D-26 Simple2D 最后的工作,开发结束
开始的时候打算将 Simple2D 做成一个库的,但现在没有那个功夫了. 要渲染顶点数据,就必须将渲染函数放置到 glClear( ) 函数和 SwapBuffers( ) 函数之间,但又不希望开发时 ...
- Web Deploy
Web Deploy 服务器安装设置与使用 Win2008R2配置WebDeploy Visual Studio 使用Web Deploy发布项目
- 批量部署ssh私钥认证
vim batch_sshkey.sh #!/bin/bashcd /rootcat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keysfor ...