-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalid_palindrome.cpp
37 lines (35 loc) · 961 Bytes
/
valid_palindrome.cpp
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
//program for detect if a string is valid palindrome or not
//problem link: https://leetcode.com/problems/valid-palindrome
class Solution {
public:
bool isPalindrome(string s) {
stack<char>st;
queue<char>q;
for(int i = 0; i< s.size(); i++)
{
if(s[i] >= 'a' && s[i] <= 'z')
{
st.push(s[i]);
q.push(s[i]);
}
else if(s[i] >= 'A' && s[i] <= 'Z')
{
st.push(s[i] + 32);
q.push(s[i] + 32);
}
else if(s[i] >= '0' && s[i] <= '9')
{
st.push(s[i]);
q.push(s[i]);
}
}
if(st.size() == 1 || st.size() == 0) return true;
while(!st.empty())
{
cout<< q.front()<<" ";
if(q.front() != st.top()) return false;
st.pop(); q.pop();
}
return true;
}
};