-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy path125-Valid-Palindrome.cpp
More file actions
31 lines (30 loc) · 714 Bytes
/
125-Valid-Palindrome.cpp
File metadata and controls
31 lines (30 loc) · 714 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
class Solution {
public:
bool isPalindrome(string s) {
//checking and making the string
for(int i =0;i<s.length();i++){
if((s[i]<'A'||s[i]>'Z')&&(s[i]<'a'|| s[i]>'z')&&(s[i]<'0' || s[i]>'9')){
s.erase(i,1);
i--;
}
}
if(s.compare("")==0){
return true;
}
//all small
for(int i =0;i<s.length();i++){
s[i]=tolower(s[i]);
}
//palindrome check
int i =0;
int j = s.length()-1;
while(s[i]){
if(s[i]!=s[j]){
return false;
}
i++;
j--;
}
return true;
}
};