forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
30 lines (29 loc) · 741 Bytes
/
solution.cpp
File metadata and controls
30 lines (29 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution
{
public:
bool isPalindrome(string s)
{
if(s.length() == 0)
return true;
for(int i=0,j=s.length()-1;i<j;i++,j--)
{
while( (s[i]<'0'
|| (s[i]>'9' && s[i]<'A')
|| (s[i]>'Z' && s[i]<'a')
|| (s[i]>'z') )
&& i<j )
i++;
while((s[j]<'0'
|| (s[j]>'9' && s[j]<'A')
|| (s[j]>'Z' && s[j]<'a')
|| (s[j]>'z') )
&& i<j )
j--;
if(s[i] != s[j]
&& s[i]-'A' != s[j]-'a'
&& s[i]-'a' != s[j]-'A')
return false;
}
return true;
}
};