JAVA---------------Easy Version To UnderStand!!!!


  • 2
    H
    public static boolean isPalindrome(String s) {
    	if (s == null)
    		return false;
    	if (s.length() == 0)// we define empty string as valid palindrome.
    		return true;
    	int low = 0, high = s.length() - 1;
    	s = s.toLowerCase();
    	while (low < high) {
    		while (low < high && !Character.isLetterOrDigit(s.charAt(low)))
    			low++;
    
    		while (low < high && !Character.isLetterOrDigit(s.charAt(high)))
    			high--;
    
    		if (s.charAt(low) != s.charAt(high))
    			return false;
    		low++;
    		high--;
    	}
    	return true;
    }

Log in to reply
 

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