/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};*/

struct ListNode* reverseList(struct ListNode* Head)
{
    struct ListNode* newHead = nullptr;
    struct ListNode* cur = Head;

    while(cur)
    {
        struct ListNode* next = cur->next;

        cur->next = newHead;
        newHead = cur;
        cur = next;
    }
    return newHead;
}
class PalindromeList {
public:
    bool chkPalindrome(ListNode* A) {
        // write code here
        ListNode* slow = A;
        ListNode* fast = A;
        ListNode* prev = nullptr;
        while(fast&&fast->next)
        {
            prev = slow;
            slow = slow->next;
            fast = fast->next->next;
        }

        prev->next = nullptr;

        slow = reverseList(slow);
        while(A)
        {
            if(A->val!=slow->val)
            {
                return false;
            }
            else {
                A = A->next;
                slow = slow->next;
            }
        }
        return true;
    }
};