Intuitive Java Solution


  • 0
    P

    Just a simple two-pointer approach.

    public boolean isPalindrome(String str) {
            str = str.toLowerCase();
            int start = 0;
            int end = str.length() - 1;
            while (start < end) {
                if (!Character.isLetterOrDigit(str.charAt(start))) start++;
                else if (!Character.isLetterOrDigit(str.charAt(end))) end--;
                else if (str.charAt(start) != str.charAt(end)) return false;
                else {
                    start++;
                    end--;
                }
            }
            return true;
        }
    

Log in to reply
 

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