-
Notifications
You must be signed in to change notification settings - Fork 105
/
Valid-palindrome.cpp
46 lines (43 loc) · 971 Bytes
/
Valid-palindrome.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
39
40
41
42
43
44
45
46
class Solution {
public:
bool valid(char ch){
if ((ch>='a' && ch<='z')||(ch>='A' && ch<='Z')||(ch>='0' && ch<='9')){
return 1;
}
return 0;
}
char lowercase(char ch){
if((ch>='a' && ch<='z')||(ch>='0' && ch<='9'))
return ch;
else {
char temp =ch-'A'+'a';
return temp;
}
}
bool checkpalindrome(string a){
int s=0;
int e=a.length()-1;
while(s<=e){
if(a[s]!=a[e]){
return 0;
}
else {
s++;
e--;
}
}
return 1;
}
bool isPalindrome(string s) {
string temp ="";
for(int j=0;j<=s.length();j++){
if(valid(s[j])){
temp.push_back(s[j]);
}
}
for(int j=0;j<temp.length();j++){
temp[j]=lowercase(temp[j]);
}
return checkpalindrome(temp);
}
};