O(n) palindrome implementation