6ms Java Solution


  • 0
    J
    class Solution {
        public boolean isPalindrome(String s) {
            char[] buf = s.toCharArray();
            int head = 0, tail = buf.length - 1;
            while (head < tail) {
                char cl = 0, cr = 0;
                while (!(cl >= 'a' && cl <= 'z' || cl >= 'A' && cl <= 'Z' || cl >= '0' && cl <= '9') && head < buf.length)
                    cl = Character.toLowerCase(buf[head++]);
                while (!(cr >= 'a' && cr <= 'z' || cr >= 'A' && cr <= 'Z' || cr >= '0' && cr <= '9') && tail >= 0)
                    cr = Character.toLowerCase(buf[tail--]);
                if (head < buf.length && cl != cr) return false;
            }
            return true;
        }
    }
    

Log in to reply
 

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