-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path125_valid_palindrome.cpp
More file actions
60 lines (54 loc) · 1.25 KB
/
125_valid_palindrome.cpp
File metadata and controls
60 lines (54 loc) · 1.25 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <iomanip>
#include <chrono>
#include <unordered_set>
using namespace std;
class Solution
{
public:
bool isPalindrome(string s)
{
string res{""};
size_t start{0};
size_t end{s.size() - 1};
while (start < end)
{
if (!isalnum(s[start]))
{
start++;
continue;
}
if (!isalnum(s[end]))
{
end--;
continue;
}
if (tolower(s[start]) != tolower(s[end]))
return false;
start++;
end--;
}
return true;
}
};
int main()
{
auto start = chrono::high_resolution_clock::now();
Solution s;
string str = " asdfkl;asdjf; asdf;lkj";
bool res = s.isPalindrome(str);
cout << res << endl;
// Timer
auto end = chrono::high_resolution_clock::now();
double time_taken =
chrono::duration_cast<chrono::nanoseconds>(end - start).count();
time_taken *= 1e-9;
cout << "Time taken by program is : " << fixed
<< time_taken << setprecision(9);
cout << " sec" << endl;
return 0;
}