public class Solution { public boolean isPalindrome(String s) { if(s == null || s.length() <2 ){ return true; } String mystring = s.replaceAll("[^A-Za-z0-9]", ""); mystring = mystring.toLowerCase(); // 只需遍历前一半就可以了 for(int i = 0 ; i< mystring.length()/2; i++){ if(mystring.charAt(i) != mystring.charAt(mystring.length() - 1 - i)){ return false; } } return true; } }