bool isPalindrome(string some_string) {
if (some_string.length() == 0 || some_string.length() == 1) {
return true;
}
if (some_string[0] == some_string[some_string.length() - 1]) {
return isPalindrome(some_string.substr(1, some_string.length() - 1));
}
else {
return false;
}
}
First off, this code is to check if a string is palindrome or not. I looked up some links and thought I could use substr to get the characters after the first index and before the last character index, what am I doing wrong? This is my first time here so I’m sorry if this question was not well initiated.
New contributor
Huzaifa Siddiqui is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.