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. 使用ssh从外网访问内网

    一.场景如下: 各个角色的对应关系如下: 角色 描述 APP 个人笔记本,属于内网IP sshd server 公网 VPS ( 映射端口: port 2222 ),拥有公网IP ssh client ...

  2. ylb: 数据库备份(Backup)和还原(Restore)

    ylbtech-SQL Server:SQL Server- 数据库备份(Backup)和还原(Restore) -- ======================================== ...

  3. ElasticSearch查询max_result_window问题处理

    需要出一份印地语文章的表,导出规则为: 1.所有印地语(包含各种颜色,各种状态)的文章 2.阅读数大于300 3.按照阅读推荐比进行排序,取前3000篇文章 说明: 1.文章信息,和阅读推荐数量在两个 ...

  4. MySQL主从同步异常问题解决Client requested master to start replication from position > file size

    MySQL主从同步异常问题解决Client requested master to start replication from position > file size 一.问题描述 MySQ ...

  5. 2017.2.20 activiti实战--第二章--搭建Activiti开发环境及简单示例(一)搭建开发环境

    学习资料:<Activiti实战> 第一章 认识Activiti 2.1 下载Activiti 官网:http://activiti.org/download.html 进入下载页后,可以 ...

  6. 使用Hadoop自己的类操作HDFS

    package hdfs; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.I ...

  7. android权限申请Permission

    代码地址如下:http://www.demodashi.com/demo/12432.html android在6.0系统以后,权限申请变得麻烦起来,今天介绍一个超级好用的权限申请库,我在使用中经过再 ...

  8. Cardboard虚拟现实开发初步(一)

    Google Cardboard 虚拟现实眼镜开发初步(一) 虚拟现实技术简单介绍 不得不说这几年虚拟现实技术逐渐火热,伴随着虚拟现实设备的价格迅速平民化,越来越多的虚拟现实设备来到了我们眼前,也因此 ...

  9. Build Your Hexo Blog (On Github)

    超简单,比jekyll好多了! 看个Demo http://kevinjmh.github.io/ 了解Hexo Hexo是一个由Node.js驱动的,简单.快速.强大的Blog框架.可以快速的生成静 ...

  10. swift菜鸟入门视频教程-05-控制流

    本人自己录制的swift菜鸟入门.欢迎大家拍砖.有什么问题能够在这里留言. 主要内容: For 循环 While 循环 条件语句 控制转移语句(Control Transfer Statements) ...