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

public boolean isPalindrome ( String s ) { if ( s == null || s . length ( ) == 0 ) { return true ; } int i = 0 ; int j = s . length ( ) - 1 ; s = s . toLowerCase ( ) ; while ( i < j ) { while ( i < j && ! Character . isLetterOrDigit ( s . charAt ( i ) ) ) { i ++ ; } if ( i >= j ) { return true ; } while ( i < j && ! Character . isLetterOrDigit ( s . charAt ( j ) ) ) { j -- ; } if ( s . charAt ( i ) != s . charAt ( j ) ) { return false ; } i ++ ; j -- ; } return true ; }
two pointers . ask for clarification : what characters do we have for input ? space ? case sensitive or not ? first convert the string to lowercase . then start from both ends and move pointers to the next alphanumeric character . if these characters are not the same , return false . remember to move pointers one more step for the next round .
