Idea: reverse the latter half part; compare with the former half part; reverse the latter half part.

Because the test case must delete the linked-list in C++, so the third step (recover the latter half part) is essential. Otherwise, it will form a cycle in the linked-list and result a "Time limit exceeded".

```
bool isPalindrome(ListNode* head) {
size_t n = 0;
ListNode * p = head;
while(p) p = p->next, ++n;
if (n == 1 || n == 0) return true;
if (n == 2) return head->val == head->next->val;
ListNode * r = head;
for(int i = 0; i < n/2; ++i) r = r->next;
if (n % 2 != 0) r = r->next;
//reverse the latter half part
p = r->next;
while(p)
{
ListNode * tmp = p->next;
p->next = r;
r = p;
p = tmp;
}
int index = 0;
p = head;
ListNode * e = r;
for(index = 0; index < n/2 && p->val == r->val; ++index)
{
p = p->next;
r = r->next;
}
bool res = index == n/2;
//reverse the latter half part again
p = e->next;
e->next = nullptr;
for(index = 0; index < n / 2 - 1; ++index)
{
ListNode * tmp = p->next;
p->next = e;
e = p;
p = tmp;
}
return res;
}
```