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.

Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.

For the purpose of this problem, we define empty string as valid palindrome.

应该算是leetcode上最简单的题之一了吧。双指针可搞定。。

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

[Leetcode][JAVA] Valid Palindrome的更多相关文章

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

  2. leetcode 125. Valid Palindrome ----- java

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

  3. Java [Leetcode 125]Valid Palindrome

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

  4. LeetCode 1216. Valid Palindrome III

    原题链接在这里:https://leetcode.com/problems/valid-palindrome-iii/ 题目: Given a string s and an integer k, f ...

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

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

  6. [leetcode] 1. Valid Palindrome

    leetcode的第一题,回文数判断. 原题如下: For example, "A man, a plan, a canal: Panama" is a palindrome. & ...

  7. 【leetcode】Valid Palindrome

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

  8. 【题解】【字符串】【Leetcode】Valid Palindrome

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

  9. LeetCode 125. Valid Palindrome

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

随机推荐

  1. 五、selecting with the API

    1. 命令通常从selection list中得到input, 调用MGlobal::getActiveSelectionList(MSelectionList &dest, bool ord ...

  2. php标记,变量,常量

    php标记 语法:有4种书写格式 1.<?php ... ?>  强烈推荐使用. 如果当前 php的代码段,是整个文档的最后一段,可以省略结束标记?(建议省略) 每句语句都要以分号;结束. ...

  3. virtualenv创建虚拟环境安装flask

    virtualenv 有什么用?如果你象我一样热爱 Python ,那么除了基于 Flask 的项目外 还会有其他项目用到 Python .当项目越来越多时就会面对使用不同版本的 Python 的 问 ...

  4. C++ 约瑟夫环问题

    约瑟夫环比较经典了 已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到m的那个人出列:他的下一个人又从1开始报数,数到m的那个人又出列:依此规律重复下去,直 ...

  5. Spark Streaming源码解读之流数据不断接收全生命周期彻底研究和思考

    本期内容 : 数据接收架构设计模式 数据接收源码彻底研究 一.Spark Streaming数据接收设计模式   Spark Streaming接收数据也相似MVC架构: 1. Mode相当于Rece ...

  6. windows 10启动盘制作工具

    Rufus 官方网站:http://rufus.akeo.ie/

  7. IOS App Integrate Google Map Problems and Method to solve them

    1. You must get a key in google developer center, and register it in below function in AppDelegate.m ...

  8. uniDBGrid导入数据库(转红鱼儿)

    有朋友问如何将excel导入数据库,这是我做的uniGUI项目中代码,实现uniDBGrid导入数据库的函数,因为用了kbmMW,所以你看到是将uniDBGrid导入kbmMWClientQuery, ...

  9. poj3241 曼哈顿最小距离生成树第k大的边

    思路: 已知: 要生成曼哈顿距离最小生成树,一个点最多和四周8个点连线,那8个点分别是将那个点四周360度平分成8个区间,每个区间里面和那个点曼哈顿距离最小的点,所以如果有n个点,那么最多有4n条边, ...

  10. JS复习

    一.三个对话框1.alert("")警告对话框2.confirm("")确定对话框3.prompt("","")可输入内 ...