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 }