-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidPalindromeLeetcode.cpp
More file actions
38 lines (36 loc) · 1.02 KB
/
ValidPalindromeLeetcode.cpp
File metadata and controls
38 lines (36 loc) · 1.02 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
class Solution {
public:
string removeSpecialCharacter(string s)
{
string temp;
for(int i=0;i<s.size();i++)
{
if(s[i]>='a'&& s[i]<='z' || s[i]>='0'&&s[i]<='9')
temp += s[i];
else if(s[i]>='A'&&s[i]<='Z')
temp += s[i]-'A'+'a';
else
continue;
}
return temp;
}
// bool checkIfPalindrome(string s, int i, int n) {
// if(i >= n/2) return true;
// if(s[i] != s[n-i-1]) return false;
// return checkIfPalindrome(s, i+1, n);
// }
bool isPalindrome(string s) {
s = removeSpecialCharacter(s);
// transform(s.begin(), s.end(), s.begin(), ::tolower);
// int n = s.length();
// bool ans = checkIfPalindrome(s, 0, n);
for(int i=0,max=s.size()-1;i<s.size()/2;i++,max--){
if(s[i]==s[max])
continue;
else
return false;
}
return true;
// return ans;
}
};