leetcode Valid Palindrome

2015-01-27 06:14:42 · 作者: · 浏览: 7

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.



简单题,输入一个字符串,不考虑数字、字母以外的任何符号。

判断是否是回文串输出即可。


设置双指针查询即可。


public class Solution {
    public boolean isPalindrome(String s) {
        s=s.toLowerCase();
        int len = s.length() -1;
        if(len==-1)
            return true;
        for(int i=0,j=len;i<=j;i++,j--){
            for(;!((s.charAt(i)>='0'&&s.charAt(i)<='9')||(s.charAt(i)>='a'&&s.charAt(i)<='z'))&&i
  
   ='0'&&s.charAt(j)<='9')||(s.charAt(j)>='a'&&s.charAt(j)<='z'))&&i