diff --git a/125_valid_palindrome/main.cpp b/125_valid_palindrome/main.cpp new file mode 100644 index 0000000..f6f9ca7 --- /dev/null +++ b/125_valid_palindrome/main.cpp @@ -0,0 +1,28 @@ +#include +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; + } +};