Skip to content

Commit b5b5a3e

Browse files
committed
feat:add Solution.cpp for 0125. Valid Palindrome
1 parent 26bd3a0 commit b5b5a3e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)