-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC3.CPP
More file actions
39 lines (32 loc) · 980 Bytes
/
LC3.CPP
File metadata and controls
39 lines (32 loc) · 980 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
//Valid palindrome
//Problem link : https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/549/week-1-august-1st-august-7th/3411/
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool isPalindrome(string s) {
if (s=="")
return true;
int len=s.length();
string str="";
for (int i=0; i<len; i++){
if (isalpha(s[i])||isdigit(s[i])){
str+=s[i];
}
}
transform(str.begin(), str.end(), str.begin(), ::tolower);
int nlen=str.length();
for (int i=0; i<nlen/2; i++){
if (str[i]!=str[nlen-i-1])
return false;
}
return true;
}
};
int main()
{
Solution obj;
cout << obj.isPalindrome("A man, a plan, a canal: Panama") << endl;
cout << obj.isPalindrome("race a car") << endl;
return 0;
}