基本一次过吧,题目没说数字要算进去啊。。
1 class Solution { 2 public: 3 bool check(string t) { 4 for (int i = 0; i < t.size(); i++) { 5 if (t[i] != t[t.size()-1-i]) return false; 6 } 7 return true; 8 } 9 bool isPalindrome(string s) { 10 // Start typing your C/C++ solution below 11 // DO NOT write int main() function 12 string t; 13 for (int i = 0; i < s.size(); i++) { 14 if (s[i] >= 'A' && s[i] <= 'Z') t += (s[i] + 'a' - 'A'); 15 if (s[i] >= 'a' && s[i] <= 'z') t += s[i]; 16 if (s[i] >= '0' && s[i] <= '9') t += s[i]; 17 } 18 return check(t); 19 } 20 };