class Solution {
public:
bool check(char &x){
if(x >= 'A' && x <= 'Z') x = x - 'A' + 'a';
if(x >= 'a' && x <= 'z') return true;
if(x >= '0' && x <= '9') return true;
return false;
}
bool isPalindrome(string s) {
int i = 0,j = s.length()-1;
while(i < j){
while(i < j ){
if(check(s[i]))break;
i++;
}
while(j > i){
if(check(s[j]))break;
j--;
}
if(j > i)
if(s[i] != s[j]) return false;
else i++,j--;
}
return true;
}
};You are here! Your runtime beats 100.00% of cppsubmissions.
本文介绍了一个使用C++实现的字符串回文检查算法。该算法通过定义一个Solution类,包含两个成员函数:check用于验证字符是否为字母或数字,并进行大小写转换;isPalindrome用于判断字符串是否为回文。此外,还提供了性能测试结果。
375

被折叠的 条评论
为什么被折叠?



