September 2019
Intermediate to advanced
816 pages
18h 47m
English
Just as a quick reminder, a palindrome (whether a string or a number) looks unchanged when it's reversed. This means that processing (reading) a palindrome can be done from both directions and the same result will be obtained (for example, the word madam is a palindrome, while the word madame is not).
An easy to implement solution consists of comparing the letters of the given string in a meet-in-the-middle approach. Basically, this solution compares the first character with the last one, the second character with the last by one, and so on until the middle of the string is reached. The implementation relies on the while statement:
public static boolean isPalindrome(String str) { int left = 0; ...