1,Vaild Palindrome

leetcode 字符串类型题
 1 bool isPalindrome(string& s) {
 2     transform(s.begin(), s.end(), s.begin(), tolower); // 把字符全部转换成小写
 3     int left = 0;
 4     int right = s.length()-1;
 5     while (left < right) {
 6         if (!isalnum(s[left])) ++left;
 7         else if (!isalnum(s[right])) --right;
 8         else if (s[left] != s[right]) return false;
 9         else {
10             ++left;
11             --right;
12         }
13     }
14     return true;
15 }
isPalindrome

相关文章: