-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy path0125.cpp
More file actions
29 lines (28 loc) · 701 Bytes
/
0125.cpp
File metadata and controls
29 lines (28 loc) · 701 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
#include <string>
#include <iostream>
#include <cctype>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
bool isPalindrome(string s)
{
if (s.empty()) return true;
int s_size = s.size();
int i = 0;
while (i < s_size)
{
if (!isalnum(s[s_size])) { s_size--; continue; }
if (!isalnum(s[i])) { i++; continue; }
if (tolower(s[i++]) != tolower(s[s_size--])) return false;
}
return true;
}
};
int main()
{
string s = "A man, a plan, a canal: Panama";
cout << Solution().isPalindrome(s) << endl;
return 0;
}