-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValid Palindrome.cpp
More file actions
42 lines (39 loc) · 855 Bytes
/
Valid Palindrome.cpp
File metadata and controls
42 lines (39 loc) · 855 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
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<string>
using namespace std;
bool isPalindrome(string s) {
int len=s.size();
for (int i=0;i<len;)
{
if ((s[i]>='0'&&s[i]<='9')||(s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z'))
i++;
else
{
s.erase(s.begin()+i);
len--;
}
}
if (s.size()==0)
return true;
int p1=0,p2=s.size()-1;
while (p1<=p2)
{
if (s[p1]==s[p2] || (s[p1]-'a')==(s[p2]-'A') || (s[p1]-'A')==(s[p2]-'a'))
{
p1++;
p2--;
}
else
{
return false;
}
}
return true;
}
int main()
{
string a="Bab";
bool b=isPalindrome(a);
cout<<b;
return 0;
}