We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent acf2a52 commit 327791aCopy full SHA for 327791a
string/Valid Palindrome
@@ -0,0 +1,38 @@
1
+// 想要学会 isalnum 的用法,但是。。
2
+
3
+ class Solution {
4
+ private:
5
+ int checkAlpha(char c)
6
+ {
7
+ if(c >= '0' && c <='9')
8
+ return c;
9
+ if(c >= 'A' &&c <= 'Z' )
10
+ return c - 'A';
11
+ if(c >= 'a' && c <= 'z')
12
+ return c - 'a';
13
+ return -1;
14
+ }
15
16
+ public:
17
+ bool isPalindrome(string s) {
18
+ for(int i = 0,j = s.size() - 1; j - i >= 1;)
19
20
+ int valueA = checkAlpha(s[i]);
21
+ int valueB = checkAlpha(s[j]);
22
+ if (valueA == valueB)
23
24
+ ++i;--j;
25
26
+ else
27
28
+ if(valueA >= 0 &valueB >= 0)
29
+ return false;
30
31
+ if(valueA <0) ++i;
32
33
+ if(valueB < 0) --j;
34
35
36
+ return true;
37
38
+ };
0 commit comments