#include <cctype>
class Solution {
public:
/**
*
* @param s string字符串
* @return bool布尔型
*/
bool isPalindrome(string s) {
// write code here
string cleaned;
// 清理字符串
for (char c : s) {
if (isalnum(c)) {
cleaned += tolower(c);
}
}
// 双指针比较
int left = 0, right = cleaned.length() - 1;
while (left < right) {
if (cleaned[left] != cleaned[right]) {
return false;
}
left++;
right--;
}
return true; // 处理空字符串的情况
}
};

京公网安备 11010502036488号