how to find that a given string is palindrome given a string can contain space as well. we don;t need to consider space. eg: a cd ef ed ca is a palindromebool isPalindrome(char *str)
{
if(!str)
return false;
int i = 0, j = strlen(str)-1;
while(i<j)
{
if(str[i]==" ")
i++;
if(str[j]==" ")
j--;
if(str[i]!=" "&&str[j]!=" ")
{
if(str[i]==str[j])
{
i++;
j--;
}
else
return false;
}
}
if(i>=j)
return true;
}
No comments:
Post a Comment