second version for palindrome algorithm