File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ ```
2
+ #include <iostream>
3
+ #include <string>
4
+
5
+ using namespace std;
6
+
7
+ class Solution {
8
+ public:
9
+ bool isPalindrome(string s) {
10
+ int l = 0, r = s.size() - 1;
11
+ bool flag = false;
12
+ while (l <= r) {
13
+ if (!isAlphaNum(s[l])) {
14
+ ++l; continue;
15
+ }
16
+ if (!isAlphaNum(s[r])) {
17
+ --r; continue;
18
+ }
19
+ if ((s[r] + 32 - 'a') % 32 != (s[l] + 32 - 'a') % 32) {flag = true; break;}
20
+ ++l; --r;
21
+ }
22
+ return !flag;
23
+ }
24
+ bool isAlphaNum(char c) {
25
+ if (c >= 'a' && c <= 'z') return true;
26
+ if (c >= 'A' && c <= 'Z') return true;
27
+ if (c >= '0' && c <= '9') return true;
28
+ return false;
29
+ }
30
+ };
31
+
32
+ int main() {
33
+ Solution s;
34
+ cout << s.isPalindrome("race a car");
35
+ //A man, a plan, a canal: Panama
36
+ }
37
+ ```
You can’t perform that action at this time.
0 commit comments