My Java Solution 8ms


  • 0
    M

    public class Solution {
    public boolean isPalindrome(String s) {
    if(null==s||s.length()<2){
    return true;
    }
    s=s.toLowerCase();
    for(int i=0,j=s.length()-1;i<j;i++,j--){
    while(i<j&&!isAlpha(s.charAt(i))){
    i++;
    }
    while(i<j&&!isAlpha(s.charAt(j))){
    j--;
    }
    if(s.charAt(i)!=s.charAt(j)){
    return false;
    }
    }
    return true;
    }

    private boolean isAlpha(char c){
        if((c>='0'&&c<='9')||(c>='a'&&c<='z')){
            return true;
        }else{
        return false;
        }
    }
    

    }


Log in to reply
 

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