//palindrome回文
//我们只能考虑alphanumeric (字母与数字)。所以必须要找一个判别字母和数字的方法。int value=Integer.valueOf("1");//49
//所以我的想法用数组,存下有效的ASCII,做做比较
//
//还需注意ignoring cases.
public class Solution {
public boolean isPalindrome(String s) {
int len=s.length();
if(len<=1)return true;//空集和一个元素都应该属于回文吧
int[] a= new int[len];
int j=0;
for(int i=0;i<len;i++)
{
int Ascii=Integer.valueOf(s.charAt(i));
if(Ascii>=65 && Ascii<=90)
{
a[j]=Ascii+32;
j=j+1;
}
else if((Ascii>=48 && Ascii<=57)||(Ascii>=97 && Ascii<=122))
{
a[j]=Ascii;
j=j+1;
}
}
float middle = j;
middle = ( middle-1)/2;//这里不能写成float middle=( j-1)/2,因为( j-1)/2运算是整型的,当j=2,结果不是0.5而是0
int m=0;
for(int l=0; l<=middle;l++)
{
if(a[l]!=a[j-1-l]) return false;
}
if(m==0)return true;
return false;
}
}
O(n) runtime, O(1) space:
//下面是leetcode上给出的solution
//The idea is simple, have two pointers – one a//t the head while the other one at the tail. Move them towards each other until they meet
//palindrome回文//我们只能考虑alphanumeric (字母与数字)。所以必须要找一个判别字母和数字的方法。int value=Integer.valueOf("1");//49//所以我的想法用数组,存下有效的ASCII,做做比较////还需注意ignoring cases.public class Solution { public boolean isPal