/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/ class PalindromeList { public: bool chkPalindrome(ListNode* head) { if(head==NULL)return true; struct ListNode* slow=head; struct ListNode* fast=head; while(fast&&fast->next) { slow=slow->next; if(fast->next) fast=fast->next->next; else fast=NULL; } struct ListNode* pre=slow; struct ListNode* cur=pre->next; struct ListNode* next=cur->next; slow->next=slow; while(cur) { cur->next=pre; pre=cur; cur=next; if(next) next=next->next; else next=NULL; } struct ListNode* newhead=head; while(pre!=newhead&&pre&&newhead) { if(pre->val!=newhead->val) return false; pre=pre->next; newhead=newhead->next; } return true; } };