A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction.
To check whether a word is a palindrome I get th
here, checking for the largest palindrome in a string, always starting from 1st char.
public static String largestPalindromeInString(String in) {
int right = in.length() - 1;
int left = 0;
char[] word = in.toCharArray();
while (right > left && word[right] != word[left]) {
right--;
}
int lenght = right + 1;
while (right > left && word[right] == word[left]) {
left++;
right--;
}
if (0 >= right - left) {
return new String(Arrays.copyOf(word, lenght ));
} else {
return largestPalindromeInString(
new String(Arrays.copyOf(word, in.length() - 1)));
}
}