my naive solution, 41.20%, 11ms, Java


  • 0
    J
     private static boolean isPalindrome(String str) {
            if (null == str) return false;
            str = str.toLowerCase();
            for (int i = 0, j = str.length() - 1; i < j; i++, j--) {
                while (!isDigitOrLetter(str.charAt(i)) && i < j) i++;
                while (!isDigitOrLetter(str.charAt(j)) && i < j) j--;
                if (str.charAt(j) != str.charAt(i)) return false;
            }
            return true;
        }
    
        private static boolean isDigitOrLetter(Character ic) {
            return (ic > 47 && ic < 58) || (ic > 64 && ic < 91) || (ic > 96 && ic < 122);
        }
    

Log in to reply
 

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