string/longest_palindrome: simplify the implementation of longest_palindrome4