My Accepted Java Solution (9ms)


  • 0
    S
    class Solution {
        public boolean isPalindrome(String s) {
            int start = 0, end = s.length()-1;
            s=s.toLowerCase();
            while(start <= end) {
                while((start<=end) && !(('a'<=s.charAt(start) && s.charAt(start)<='z') || ('0'<=s.charAt(start) && s.charAt(start)<='9'))) start++;
                while((start<=end) && !(('a'<=s.charAt(end) && s.charAt(end)<='z') || ('0'<=s.charAt(end) && s.charAt(end)<='9'))) end--;
                if(start>end) break;
                if(s.charAt(start) != s.charAt(end)) return false;
                start++;
                end--;
            }
            return true;
        }
    }
    

Log in to reply
 

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