/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
bool isPalindrome(ListNode* head) {
int length = 0;
ListNode *p,*q,*t,*m;
p = head;
if(head==NULL)return true;
while(p!=NULL)
{
length ++;
p = p->next;
}
if(length ==1)return true;
int mid = length/2-1;
int l =0;
p = head;
q = p;
t = p->next;
q->next=NULL;
while(l<mid)
{
p = t;
// q->next = NULL;
t = p->next;
p->next = q;
q = p;
l ++;
}
if(length%2!=0)
{
t = t->next;
}
while(t!=NULL&&p!=NULL)
{
if(t->val==p->val)
{
t = t->next;
p = p->next;
}
else return false;
}
return true;
}
};