0125.cpp (399B)
1 class Solution { 2 public: 3 bool isPalindrome(string s) { 4 int i = 0, j = s.size() - 1; 5 while (i < j) { 6 if (!isalnum(s[j])) 7 j--; 8 else if (!isalnum(s[i])) 9 i++; 10 else if (tolower(s[i]) != tolower(s[j])) 11 return false; 12 else 13 i++, j--; 14 } 15 return true; 16 } 17 };