class Solution{
public:
//Function to check whether the list is palindrome.
bool isPalindrome(Node *head)
{
//Your code here
stack<int> s;
Node *t;
t=head;
while(t)
{
s.push(t->data);
t=t->next;
}
t=head;
while(t)
{
if(s.top()==t->data)
{
s.pop();
}
t=t->next;
}
if(s.empty()) return true;
else return false;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter