Check if Linked List is Palindrome

PHOTO EMBED

Fri Jan 20 2023 17:35:27 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

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;
        
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/check-if-linked-list-is-pallindrome/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article