/**
* 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) {
if(!head || !head->next) return true;
ListNode *slow=head, *fast=head;
while(fast->next && fast->next->next){
slow = slow->next;
fast = fast->next->next;
}
ListNode *pre = slow, *cur=slow->next;
while(cur){
ListNode* next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
}
slow->next = NULL;
while(head){
if(head->val!=pre->val) return false;
head = head->next;
pre = pre->next;
}
return true;
}
};