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. 【freeCodeCamp】免费晋级前台工程师呦!!!!

    首页地址:https://www.freecodecamp.org/ GitHub:https://github.com/freeCodeCamp/freeCodeCamp ============= ...

  2. sencha toucha获取 constructor中的数据

    config:{ tmp:null }, constructor : function(conf) { this.config.tmp=conf; } 添加配置属性,然后直接用 this.config ...

  3. 漫谈程序员系列:3D打印能打印出程序员吗

    首先声明,本文是一本正经的胡扯,绝不是随随便便的胡扯,请您不要随便攻击我胡说八道.我要反复星爷在<喜剧之王>里的台词:事实上.我是一本正经的喷子. 3D打印的定义 关于3D打印,以下是来自 ...

  4. linux 打开文件数too many open files解决方法

    出现这句提示的原因是程序打开的文件/socket连接数量超过系统设定值.查看每个用户最大允许打开的文件数量ulimit -a 其中 open files (-n) 1024 表示每个用户最大允许打开的 ...

  5. JAVA Eclipse开发Android如何让屏幕保持为竖直或水平状态

    在Manifest.xml文件中找到activity部分,添加下面这一行 android:screenOrientation="landscape" landscape是横向,po ...

  6. C 命令行参数

    C 命令行参数 执行程序时,可以从命令行传值给 C 程序.这些值被称为命令行参数,它们对程序很重要,特别是当您想从外部控制程序,而不是在代码内对这些值进行硬编码时,就显得尤为重要了. 命令行参数是使用 ...

  7. Php网站如何优化才好?

    尽量静态化:    如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.   当然了,这个测试方法需要在十万级以上次执行,效果才明显.   其实静态方法和非 ...

  8. 【Excle数据透视】二维数据如何创建数据透视表

    二维数据在创建数据透视表的时候,可能会给你带来一些麻烦,没法创建,会丢失维度,那怎么办呢? 解决办法:使用数据透视表和数据透视图向导即可创建 具体操作如下: 按下[Alt+D+P],出现如下界面 选择 ...

  9. mysql主从只同步部分库或表

    同步部分数据有两个思路,1.master只发送需要的:2.slave只接收想要的. master端: binlog-do-db      二进制日志记录的数据库(多数据库用逗号,隔开)binlog-i ...

  10. .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度

    .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度   随机颜色在日常开发中很常用到,有时候要控制颜色明亮度,比如在白色背景网页上的随机颜色,一般要求颜色稍微暗一 ...