题解 | #判断回文串#
判断回文串
https://www.nowcoder.com/practice/b4dc0f1ee20448fca1f387fb1546f43f
#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; // 处理空字符串的情况 } };