Easy Java Solution using Regex


  • 0
    public class Solution {
        public boolean isPalindrome(String s) {
            String str= s.replaceAll("[^a-zA-Z0-9\\s]", "").replaceAll("( )+", "").toLowerCase();
    		for(int i=0;i<str.length()/2;i++){
    			if(str.charAt(i)!=str.charAt(str.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.