Palindrome

Palindrome

Definition of Palindrome

left-to-right, and right-to-left, and it’s the same. For examples:

Abba
A man, a plan, a canal - Panama!

Solution

You need 2 pointers, one at the beginning, another one in the end. Move them one by one towards the center and check if it's palindrome.

boolean check(String text) {
	int a = 0;
	int b = text.length - 1;
	while(b > a) {
		if (!isLetter(text[a])) {
			++a;
			continue;
		}
		if (!isLetter(text[b])) {
			--b;
			continue;
		}
		if (!equalsIngoreCase(text[a], text[b]) {
			return false;
		}
		++a;
		--b;
	}
	return true;
}