-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path125.cpp
More file actions
83 lines (80 loc) · 1.74 KB
/
125.cpp
File metadata and controls
83 lines (80 loc) · 1.74 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include"iostream"
#include<string>
using namespace std;
bool isPalindrome(string s)
{
string str = "";
int len = s.length();
int lenStr = 0;
for(int i = 0; i < len; i++)
{
if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= '0' && s[i] <= '9'))
{
str += s[i];
lenStr++;
}
else if(s[i] >= 'A' && s[i] <= 'Z')
{
str += (s[i] - 'A' + 'a');
lenStr++;
}
}
for(int i = 0; i < lenStr / 2; i++)
{
if(str[i] != str[lenStr - i - 1])
{
return false;
}
}
return true;
}
#if 0
class Solution
{
public:
bool isEffective(char c)
{
if((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'))
{
return true;
}
return false;
}
bool isPalindrome(string s)
{
if(s.empty())
{
return true;
}
int left = 0, right = s.size()-1;
while(left < right)
{
while(left < right && !isEffective(s[left]))
{
left++;
}
while(left < right && !isEffective(s[right]))
{
right--;
}
if(left < right)
{
if(tolower(s[left]) != tolower(s[right]))
{
return false;
}
left++;
right--;
}
}
return true;
}
};
#endif
int main()
{
string s1="aabb aa";//"A man, a plan, a canal: Panama";
bool po=isPalindrome(s1);
cout<<po<<endl;
return 0;
}