/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param head ListNode类 the head
     * @return bool布尔型
     */
    bool isPail(ListNode* head) {
        if(!head||!(head->next))return 1;
        ListNode *slow=head,*fast=head,*mid;
        while(fast->next&&fast->next->next){
            slow=slow->next;
            fast=fast->next->next;
        }
        slow=ReverseList(slow->next);
        while(slow){
            if(slow->val!=head->val)return 0;
            slow=slow->next;
            head=head->next;
        }
        return 1;
    }
    ListNode* ReverseList(ListNode* pHead) {
        ListNode *pre=nullptr,*next;
        while(pHead){
            next=pHead->next;
            pHead->next=pre;
            pre=pHead;
            pHead=next;
        }
        return pre;
    }
};