Java solution 6ms


  • 0
    P

    I've took start & end approach.
    '''
    public boolean isPalindrome(String s) {
    int start = 0;
    int end = s.length()-1;

        while(start < end) {
            
            int startVal = s.charAt(start);
            int endVal = s.charAt(end);
            
            if((startVal >= 48 && startVal <= 57)) {
                startVal = s.charAt(start) - '0';
            }
            if((endVal >= 48 && endVal <= 57)) {
                endVal = s.charAt(end) - '0';
            }
            
            if(!((startVal >= 65 && startVal <= 90) || (startVal >= 97 && startVal <= 122) ||
                    (startVal >= 0 && startVal <= 9))) {
                        startVal = -1;
                        start++;
            }
            if(!((endVal >= 65 && endVal <= 90) || (endVal >= 97 && endVal <= 122) ||
                    (endVal >= 0 && endVal <= 9))) {
                        endVal = -1;
                        end--;
            }
            if((startVal != -1) && (endVal != -1)) {
                if(!(((startVal - endVal) == -32) || ((startVal - endVal) == 32) || 
                        ((startVal - endVal) == 0))) {
                    return false;
                } 
                if(startVal != -1) start++;
                if(endVal != -1) end--;
            }
        } 
        return true;
    }
    

    '''


Log in to reply
 

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