125. Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.

 

 1 bool isPalindrome(char* s) {
 2     int len;
 3     int i,j;
 4     if(s == NULL)
 5         return s;
 6     j = strlen(s) - 1;
 7     i = 0;
 8     while(i < j)
 9     {
10         s[i] = tolower(s[i]);
11         s[j] = tolower(s[j]);
12         if(isalnum(s[i]) == 0)
13         {
14             i++;
15             continue;
16         }
17         if(isalnum(s[j]) == 0)
18         {
19             j--;
20             continue;
21         }
22         if(s[i] != s[j])
23             break;
24         i++;
25         j--;
26     }
27     if(i < j)
28         return 0;
29     return 1;
30 }

 

posted @ 2016-05-25 20:31  米开朗菠萝  阅读(150)  评论(0编辑  收藏  举报