原题地址

 

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 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-08-24
  • 2021-07-10
猜你喜欢
  • 2021-08-23
  • 2021-09-19
  • 2021-11-30
  • 2021-09-20
  • 2021-09-13
  • 2021-09-27
  • 2021-07-22
相关资源
相似解决方案