A simple java solution using regex


  • 0
    F
    public boolean isPalindrome(String s) {
        s = s.replaceAll("[^a-zA-Z0-9]", "");
        if(s == null){
        	return true;
        }
        
        char[] cArray = s.toCharArray();
        int start = 0;
        int end = cArray.length -1 ;
        while(start < end){
        	if(Character.toLowerCase(cArray[start]) !=  Character.toLowerCase(cArray[end])){
        		return false;
        	}
        	start++;
        	end--;
        }
        
        return true;
    }

Log in to reply
 

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