feat: 125_valid_palindrome

This commit is contained in:
SquidSpirit 2025-03-18 22:33:43 +08:00
parent 8c538a27c9
commit f560e933f4

View File

@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool isPalindrome(string s) {
string proceededStr;
for (auto ch : s) {
if ((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
proceededStr.push_back(ch);
} else if (ch >= 'A' && ch <= 'Z') {
proceededStr.push_back(ch - ('A' - 'a'));
}
}
cout << proceededStr << "\n";
const int len = proceededStr.length();
for (int i = 0; i < len / 2; i++) {
if (proceededStr[i] != proceededStr[len - i - 1]) {
return false;
}
}
return true;
}
};