[leetcode]125. Valid Palindrome判断回文串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
Example 1:
Input: "A man, a plan, a canal: Panama"
Output: true
题目
判断回文串,只检查字母,不分大小写。
思路
双指针
代码
class Solution {
public boolean isPalindrome(String s) {
s = s.toLowerCase();
int left = 0;
int right = s.length()-1;
while(left < right){
// check white spaces
if(!Character.isLetterOrDigit(s.charAt(left))) left++;
// check white spaces
else if(!Character.isLetterOrDigit(s.charAt(right))) right--;
else if(s.charAt(left) != (s.charAt(right))) return false;
else {
left++ ;
right--;
}
}
return true;
}
}
[leetcode]125. Valid Palindrome判断回文串的更多相关文章
- [LeetCode] 125. Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- lintcode :Valid Palindrome 有效回文串
题目: 有效回文串 给定一个字符串,判断其是否为一个回文串.只包含字母和数字,忽略大小写. 样例 "A man, a plan, a canal: Panama" 是一个回文. & ...
- [LeetCode] 214. Shortest Palindrome 最短回文串
Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- LeetCode 125. Valid Palindorme (验证回文字符串)
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 125 Valid Palindrome 验证回文字符串
给定一个字符串,确定它是否是回文,只考虑字母数字字符和忽略大小写.例如:"A man, a plan, a canal: Panama" 是回文字符串."race a c ...
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- HDOJ/HDU 2163 Palindromes(判断回文串~)
Problem Description Write a program to determine whether a word is a palindrome. A palindrome is a s ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- LeetCode(125):验证回文串
Easy! 题目描述: 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, ...
随机推荐
- echo off
就是说关闭回显 @echo off并不是DOS程序中的,而是DOS批处理中的.当年的DOS,所有操作都用键盘命令来完成,当你每次都要输入相同的命令时,可以把这么多命令存为一个批处理,从此以后,只要运行 ...
- [UE4]C++代码操作SplineMesh
转自:http://aigo.iteye.com/blog/2279503 void ARaceSpline::OnConstruction(const FTransform& Transfo ...
- SVM的sklearn.svm.SVC实现与类参数
SVC继承了父类BaseSVC SVC类主要方法: ★__init__() 主要参数: C: float参数 默认值为1.0 错误项的惩罚系数.C越大,即对分错样本的惩罚程度越大,因此在训练样本中准确 ...
- rman备份恢复命令之switch(转)
一 switch 命令1 switch命令用途更新数据文件名为rman下镜像拷贝时指定的数据文件名更新数据文件名为 set newname 命令指定的名字. 2 switch 命令使用前提条件rman ...
- Lunce编程模型
问题的场景: 解决方案:都是来自于科技论文 ============================================================================== ...
- 0_Simple__simpleVoteIntrinsics + 0_Simple__simpleVoteIntrinsics_nvrtc
介绍了线程束表决函数的实例(其概念介绍见 http://www.cnblogs.com/cuancuancuanhao/p/7841512.html),并在静态和运行时编译两种条件下进行使用. ▶ 源 ...
- mybatis - maven - eclipse 坑爹问题: No suitable driver found for http://maven.apache.org
坑爹的问题,调查了1天 一直以为是驱动问题,根源却在url上:No suitable driver found for http://maven.apache.org 根源: 1.在jdbc.prop ...
- DataSnap Server HTTP json格式修改 返回图片
DataSnap Server HTTP json 格式修改 http://127.0.0.1:8080/datasnap/rest/TServerMethods1/EchoString/hello ...
- Activity服务类-2 EngineService服务类
一共提供了9个接口 //获取RepositoryServiceRepositoryService getRepositoryService();//获取RuntimeServiceRuntimeSer ...
- js倒计时发送验证码按钮
var wait=60; function time(o) { if (wait == 0) { o.removeAttribute("disabled"); o.value=&q ...