class Solution {
public:
    bool isPail(ListNode* head) {
        if(!head) return true;
        stack<ListNode *> st;
        int size = 0;
        ListNode *p = head;
        while(p) p = p->next,size++;
        p = head;
        int i;
        for(i = 0; i < size/2; i++){
            st.push(p);
            p = p->next;
        }
        if(size%2) p = p->next;
        while(!st.empty()){
            if(p->val != st.top()->val) return false;
            st.pop();
            p = p->next;
        }
        return true;
    }
};