My accepted Java solution(6ms)


  • 0
    S
    public class Solution {
        public int isCharacter(char ch) {
            if(ch >= 'a' && ch <= 'z') return ch;
            else if(ch >= 'A' && ch <= 'Z') return (ch-'A')+'a';
            else if(ch >= '0' && ch <= '9') return ch;
            else return -1;
        }
        public boolean isPalindrome(String s) {
            int front = 0;
            int back = s.length()-1;
            while(front <= back) {
                while(front <= back && isCharacter(s.charAt(front)) == -1) front++;
                while(front <= back &&isCharacter(s.charAt(back)) == -1) back--;
                if(front <= back &&isCharacter(s.charAt(front)) != isCharacter(s.charAt(back))) return false;
                front++;
                back--;
            }
            return true;
        }
    }
    

Log in to reply
 

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