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

For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.

解题思路:

注意题目,忽略大小写,忽略非字母或数字,JAVA实现如下:

    public boolean isPalindrome(String s) {
if(s.length()<=1)
return true;
int left=0,right=s.length()-1;
while(left<right){
if(!Character.isLetterOrDigit(s.charAt(left))){
left++;
continue;
}
if(!Character.isLetterOrDigit(s.charAt(right))){
right--;
continue;
}
if(Character.toUpperCase(s.charAt(left))!=Character.toUpperCase(s.charAt(right)))
return false;
left++;
right--;
}
return true;
}

Java for LeetCode 125 Valid Palindrome的更多相关文章

  1. leetcode 125. Valid Palindrome ----- java

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

  2. Java [Leetcode 125]Valid Palindrome

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

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

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

  4. LeetCode 125. Valid Palindrome

    这个题目只要注意大小写问题即可解决,而且我们只关注的是字母和数值 Given a string, determine if it is a palindrome, considering only a ...

  5. [leetcode]125. Valid Palindrome判断回文串

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

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

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

  7. Leetcode 125 Valid Palindrome 字符串处理

    题意:判断字符串是否是回文字符串 先将所有的字母和数字字符保留,并将大写字母转化成小写字母,然后将字符串倒置,比较前后两个字符串是否相同. 该题最好的解法可以模仿 Leetcode 345 Rever ...

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

  9. 125. Valid Palindrome【easy】

    125. Valid Palindrome[easy] Given a string, determine if it is a palindrome, considering only alphan ...

随机推荐

  1. Fresco框架SimpleDraweeView控件的简单使用

    首先把网络.SD卡的读写权限添加上:<span style="font-family: Arial, Helvetica, sans-serif;">   </s ...

  2. 在网页中插入flash播放器,播放flv视频

    效果图如下: 所用代码如下: <object id="FLVPlayer" height="480" width="640" code ...

  3. NetBeans菜单栏字体太小了

    NetBeans菜单栏字体太小了,导致很难看 解决方法:在netbeans的快捷方式内加入"netbeans.exe" --fontsize 12参数.还可以通过配置NetBean ...

  4. 转: Gradle:Gradle入门

    from: http://blog.csdn.net/p106786860/article/details/50422463

  5. 分享个免费的货币汇率API

    先上API文档链接:https://www.juhe.cn/docs/api/id/23,支持人民币牌价.外汇汇率查询:数据仅供参考,交易时以银行柜台成交价为准. 人民币牌价 接口地址:http:// ...

  6. apue学习笔记(第四章 文件和目录)

    本章将描述文件系统的其他特性和文件的性质. 函数stat.fstat.fstatat和lstat #include <sys/stat.h> int stat(const char *re ...

  7. dos下连接mysql,显示表结构

    C:\Windows\system32>mysql -hlocalhoset -uroot -p Enter password: ***** mysql> use ssh Database ...

  8. template.js文档

    参见GitHub:https://github.com/yanhaijing/template.js/ template.js简介: template.js 一款javascript模板引擎,简单,好 ...

  9. AMD和Intel的CPU对比

    http://www.lotpc.com/yjzs/5825.html 推荐文章:小白看AMD与intel的cpu架构,AMD慢的原因 CPU核心的发展方向是更低的电压.更低的功耗.更先进的制造工艺. ...

  10. c# .net 我的Application_Error 全局异常抓取处理

    protected void Application_Error(object sender, EventArgs e)        {            //在出现未处理的错误时运行的代码   ...