Simple Java Solution - 32ms


  • 0
    G
    public boolean isPalindrome(String s) {
            //Remove all punctuation and spaces and convert all upper case letter into lower case
            s = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
            char[] sArr = s.toCharArray();
            for (int i=0; i <= sArr.length-1-i; i++) {
                if (sArr[i] != sArr[sArr.length-1-i])
                    return false;       
            }
            
            return true;
        }

Log in to reply
 

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