feat: 125_valid_palindrome
This commit is contained in:
parent
8c538a27c9
commit
f560e933f4
28
125_valid_palindrome/main.cpp
Normal file
28
125_valid_palindrome/main.cpp
Normal 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;
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user