Write a function to determine if a string is a palindrome.
Respostas da entrevista
Sigiloso
2 de fev. de 2013
bool palindrom(char* s, int length)
{
int l = 0;
int r = length - 1;
while (l < r)
{
if (s[l] != s[r])
return false;
++l;
--r;
}
return true;
}
1
Sigiloso
16 de fev. de 2013
Using the definition: "A Palindrome is a string where the first and last character are the same, and the middle is a palindrome", the code would look like this
bool is_palindrome(char *string, int length) {
if(length == 1 || length == 0)
return true;
if(string[0] == string[length-1])
return is_palindrome(string+1,length-2);
else
return false;
}