```
class Solution {
public:
bool isPalindrome(ListNode* head) {
int len = 0;
ListNode* p = head;
while(p)
{
++len;
p = p->next;
}
p = head;
ListNode* p1 = nullptr,*tmp;
for(int i = 0;i < len/2;++i)
{
tmp = p->next;
p->next = p1;
p1 = p;
p = tmp;
}
if(len % 2)
p = p->next;
for(int i = 0;i <len/2;++i)
{
if(p1->val != p->val)
return false;
p1 = p1->next;
p = p->next;
}
return true;
}
};
```