Skip to content

Commit 53e95d1

Browse files
authored
Create program.cpp
1 parent 8ebdacb commit 53e95d1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Valid Palindrome/program.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(string s)
4+
{
5+
if(s==" ")
6+
{
7+
return true;
8+
}
9+
vector<char>st;
10+
for(int i=0;i<s.length();i++)
11+
{
12+
if( (s[i]>='a'&& s[i]<='z') || (s[i]>='A' && s[i]<='Z') || (s[i]>='0'&& s[i]<='9') )
13+
{
14+
st.push_back(tolower(s[i]));
15+
}
16+
}
17+
vector<char>strev;
18+
copy(st.begin(),st.end(), back_inserter(strev));
19+
reverse(strev.begin(), strev.end());
20+
21+
int f=0;
22+
for(int i=0;i<st.size();i++)
23+
{
24+
if(st[i]!=strev[i])
25+
{
26+
f=1;
27+
break;
28+
}
29+
}
30+
if(f==0)
31+
{
32+
return true;
33+
}
34+
return false;
35+
}
36+
};

0 commit comments

Comments
 (0)