My Java solution(using regex), easy to understand


  • 0
    B
    public  boolean isPalindrome(String s) {
        if (s == null) return false;
        String s1 = s.replaceAll("\\W", "").toLowerCase();
        if (s1.length() == 0) return true;
        int i = -1;
        int j = s1.length();
        while (s1.charAt(++i) == s1.charAt(--j) && i < j) ;
        return i >= j;
    }

Log in to reply
 

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