LeetCode-Valid Palindrome

找自信刷数目的水题。

题目没看清,看出只是字母了,贡献了一次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 };
原文地址:https://www.cnblogs.com/chasuner/p/validpalindrome.html