/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 *	ListNode(int x) : val(x), next(nullptr) {}
 * };
 */
#include <stack>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param head ListNode类 the head
     * @return bool布尔型
     */
    bool isPail(ListNode* head) {
        stack<int>s;ListNode* temp=head;
        if(head==nullptr){
            return true;
        }// write code here
        while (temp!=nullptr) {
            s.push(temp->val);temp=temp->next;
        }
        temp=head;
        while (temp!=nullptr) {
            if (temp->val==s.top()) {
                s.pop();temp=temp->next;
            }else {
                return false;
            }
        }
        return true;
    }
};