8ms Java


  • 0
    H
    public boolean isPalindrome(String s) {
        if(s.length() == 0)
            return true;
        int i=0,j=s.length() - 1;
        while(i < j){
            int charNumS = Character.toLowerCase(s.charAt(i));
            int charNumE = Character.toLowerCase(s.charAt(j));
            if(((charNumS > 96 && charNumS < 123)
                    || (charNumS > 47 && charNumS < 58)) 
                    && ((charNumE > 96 && charNumE < 123)
                    || (charNumE > 47 && charNumE < 58))){
                if(charNumS != charNumE)
                    return false;
                i++;
                j--;
            }
            if(charNumS < 48 || (charNumS > 57 && charNumS < 97)
                    || charNumS > 122)
                       i++;   
            if(charNumE < 48 || (charNumE > 57 && charNumE < 97)
                    || charNumE > 122)
                        j--;
        }
        return true;
    }

Log in to reply
 

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