-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path125-Valid-Palindrome.cpp
More file actions
54 lines (48 loc) · 899 Bytes
/
125-Valid-Palindrome.cpp
File metadata and controls
54 lines (48 loc) · 899 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
43
44
45
46
47
48
49
50
51
52
53
54
class Solution {
public:
bool checkalpha(char ch){
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')||(ch>='0'&&ch<='9'))
return true;
else{
return false;
}
}
// Convert character to lowercase
char Tolower(char ch){
if(ch>='a'&&ch<='z'){
return ch;
}
else if (ch >= 'A' && ch <= 'Z') {
return ch + ('a' - 'A'); // Convert uppercase to lowercase
}
return ch;
}
// check if a sting is palindrome or...
bool chekpalindrome(string str){
int st=0;
int end= str.length()-1;
while(st<=end){
if(str[st]!=str[end]){
return false;
}
else{
st++;
end--;
}
}
return true;
}
bool isPalindrome(string s) {
string temp = \\;
for(int j=0;j<s.length();j++){
if(checkalpha(s[j])){
temp.push_back(s[j]);
}
}
//lowercase()
for(int j=0;j<temp.length();j++){
temp[j]=Tolower(temp[j]);
}
return chekpalindrome(temp);
}
};