5ms Java Solution


  • -1
    Y
    public boolean isPalindrome(String s) {
        if(s==null) return false;
        if(s.length()<2) return true;
        for(int i=0,j=s.length()-1;i<=j;){
            char temp1 = s.charAt(i),temp2 = s.charAt(j);
            if(temp1>64&&temp1<91) temp1=(char)(temp1+32);
            if(temp2>64&&temp2<91) temp2=(char)(temp2+32);
            if((temp1<97&&temp1>57)||temp1>122||temp1<48) {
                i++;
                continue;
            }
            if((temp2<97&&temp2>57)||temp2>122||temp2<48){
                j--;
                continue;
            }
            if(temp1!=temp2) return false;
            i++;
            j--;
        }
        return true;
    }

Log in to reply
 

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