Skip to content

Commit 46908e2

Browse files
authored
Merge pull request gzc426#228 from zjukk/patch-6
Create zjukk.md
2 parents f1748af + a20bfda commit 46908e2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

2018.11.27-leetcode125/zjukk.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
```

0 commit comments

Comments
 (0)