We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 26bd3a0 commit b5b5a3eCopy full SHA for b5b5a3e
solution/0100-0199/0125.Valid Palindrome/Solution.cpp
@@ -0,0 +1,24 @@
1
+class Solution {
2
+public:
3
+ bool isPalindrome(string s) {
4
+ int left = 0, right = s.size() - 1;
5
+ while (left < right) {
6
+ if (!isAlphaNum(s[left])) ++left;
7
+ else if (!isAlphaNum(s[right])) --right;
8
+ else if ((s[left] + 32 - 'a') % 32 != (s[right] + 32 - 'a') % 32) return false;
9
+ else {
10
+ ++left;
11
+ --right;
12
+ }
13
14
+ return true;
15
16
+
17
+private:
18
+ bool isAlphaNum(char &ch) {
19
+ if (ch >= 'a' && ch <= 'z') return true;
20
+ if (ch >= 'A' && ch <= 'Z') return true;
21
+ if (ch >= '0' && ch <= '9') return true;
22
+ return false;
23
24
+};
0 commit comments