![]() |
VOOZH | about |
A string is said to be a palindrome if the reverse of the string is the same as the original string. For Example: string "AABBAA" is a palindrome because its reversed form is identical to the original string.
Below are some methods to check if a string is palindrome or not:
A string is a palindrome if it reads the same forwards and backwards, this can be checked by reversing the string using std::reverse() and comparing it with the original.
"ABCDCBA" is palindrome. "ABCD" is NOT palindrome.
Explanation:
In this method, we place the two index pointers, left and right at the starting and ending character of the string respectively. After that, we start matching the character present at left and right position.
Code Implementation:
"ABCDCBA" is palindrome. "ABCD" is NOT palindrome.