找自信刷数目的水题。

题目没看清,看出只是字母了,贡献了一次WA!

必须认真看清题目呀~~~

 1 class Solution {
 2 public:
 3     bool isPalindrome(string s) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         if (s.size() == 0) 
 7         return true;
 8         int i = 0; 
 9         int j = s.size();
10         while (i <= j) {
11             if(isalnum(s[i])){
12                 s[i] = tolower(s[i]);
13             }
14             else {
15                 i++;
16                 continue;
17             }
18             if (isalnum(s[j])) {
19                 s[j] = tolower(s[j]);
20             }
21             else {
22                 j--;
23                 continue;
24             }
25             if (s[i] == s[j]) {
26                 i++;
27                 j--;
28             }
29             else {
30                 return false;
31             }
32         }
33         return true;
34     }
35 };

 

相关文章:

  • 2021-09-21
  • 2022-03-04
  • 2021-10-19
  • 2021-10-31
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2021-07-09
  • 2022-01-30
  • 2021-09-27
  • 2021-06-20
  • 2021-12-24
  • 2022-01-17
相关资源
相似解决方案