-
Notifications
You must be signed in to change notification settings - Fork 0
/
0125.cpp
40 lines (30 loc) · 801 Bytes
/
0125.cpp
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
31
32
33
34
35
36
37
38
#include <string>
using namespace std;
class Solution {
public:
bool isPalindrome(string s) {
int sIdx = 0, eIdx = s.length() - 1;
while (sIdx < eIdx)
{
while (sIdx < eIdx && !isalnum(s[sIdx])) sIdx++;
while (sIdx < eIdx && !isalnum(s[eIdx])) eIdx--;
if (tolower(s[sIdx]) != tolower(s[eIdx])) return false;
++sIdx;
--eIdx;
}
return true;
}
};
class Solution {
public:
bool isPalindrome(string s) {
int l = 0, r = s.length() - 1;
while (l < r)
{
while (l < r && !isalnum(s[l])) l++;
while (l < r && !isalnum(s[r])) r--;
if (tolower(s[l++]) != tolower(s[r--])) return false;
}
return true;
}
};