My java solution in one pass

  • 0
    public class Solution {
    public static boolean isPalindrome(String s) {
        if(s==""||s.length()==1) return true;
        char[] c = s.toCharArray();
        for (int i = 0, j = c.length-1; i<j; ++i,--j){
        	while (!Character.isLetterOrDigit(c[i]))
        		if (i<j) ++i;
        		else break;
        	while (!Character.isLetterOrDigit(c[j]))
        		if (i<j) --j;
        		else break;
        	if (c[i]!=c[j]&&'a'-'A'!=(int)Math.abs(c[i]-c[j])) 
        		return false;
        return true;


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.