/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param head ListNode类 the head
 * @return bool布尔型
 */

#include <stdbool.h>
struct ListNode* release(struct ListNode* p)
{
    struct ListNode* pre=p;
    struct ListNode* cur=NULL;
    struct ListNode* tmp=NULL;
    while(pre!=NULL)
    {
        tmp=pre->next;
        pre->next=cur;
        cur=pre;
        pre=tmp;
    }
    return cur;
}

bool isPail(struct ListNode* head ) 
{
    struct ListNode*fast=head;
    struct ListNode*slow=head;
    while(fast->next!=NULL&&fast->next->next!=NULL)
    {
        slow=slow->next;
        fast=fast->next->next;
    }
    struct ListNode* first=head;
    struct ListNode* second=release(slow->next);

    while(second!=NULL)
    {
        if(first->val!=second->val)
        {
            return false;
        }
        first=first->next;
        second=second->next;
    }
    return true;
}