StringBuilder to Rescue


  • 0
    M
    class Solution {
        public boolean isPalindrome(String s) {
            if(s == null){return false;}
            char c_ary[] = s.toCharArray();
            StringBuilder sb = new StringBuilder();
            for(char c: c_ary){
                if(Character.isLetterOrDigit(c)){ sb.append(c);}
            }
            return sb.toString().equalsIgnoreCase(sb.reverse().toString());
        }
    }
    

Log in to reply
 

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