/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
public:
    bool chkPalindrome(ListNode* A) {
        // write code here
        struct ListNode* head,*tail,*tmp;
        head = tail = (struct ListNode*)malloc(sizeof(struct ListNode));
        struct ListNode* cur = A;
        head->next = cur;
        tail = head->next;
        
        cur = cur->next;
        while(cur){
            tmp = cur->next;
            cur->next = tail;
            head->next = cur;
            cur = tmp;  
        }
        cur = head->next;
        tail->next = NULL;
        struct ListNode* cur2 = A;
        while(cur2){
           if(cur2->val != cur->val){
            return false;
           }
           cur = cur->next;
           cur2 = cur2->next;
        }
        
        return true;
    }
};