Leetcode#125 Valid Palindrome

原题地址

 

isalnum:判断是否是字符或数字

toupper:将字符转换成大写,非字符不变

 

代码:

 1 bool isPalindrome(string s) {
 2         string news;
 3         for (auto c : s)
 4             if (isalnum(c))
 5                 news += tolower(c);
 6         
 7         int i = 0;
 8         int j = news.length() - 1;
 9         while (i < j && news[i] == news[j]) {
10             i++;
11             j--;
12         }
13         
14         return i >= j;
15 }

 

posted @ 2015-02-02 15:28  李舜阳  阅读(115)  评论(0编辑  收藏  举报