125. 验证回文串
时间:2020-04-01 20:00:31
收藏:0
阅读:57
1 class Solution 2 { 3 public: 4 bool isPalindrome(string s) 5 { 6 string str; 7 for(int i = 0;i < s.size();i ++) 8 { 9 if(isdigit(s[i])) str.push_back(s[i]); 10 if(isalpha(s[i])) str.push_back(tolower(s[i])); 11 } 12 int n = str.size(); 13 for(int i = 0;i < n/2;i ++) 14 { 15 if(str[i] != str[n - 1 - i]) return false; 16 } 17 return true; 18 } 19 };
原文:https://www.cnblogs.com/yuhong1103/p/12615082.html
评论(0)