/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};*/
#include <cstdio>
class PalindromeList {
public:
ListNode* overtip(ListNode* A)
{
ListNode* newnode=(ListNode*)malloc(sizeof(ListNode));
newnode=nullptr;
ListNode* cur=A;
ListNode* Stc=A;
while(cur!=nullptr)
{
cur=Stc->next;
Stc->next=newnode;
newnode=Stc;
Stc=cur;
}
return newnode;
}
ListNode* overmid(ListNode* A)
{
struct ListNode* slow,*fast;
slow=fast=A;
while(fast && fast->next )//奇数偶数情况,偶数fast不会出链表,而奇数就会出链表
{
fast=fast->next->next;
slow=slow->next;
}
return slow;
}
bool chkPalindrome(ListNode* A) {
// write code here
ListNode* mid=overmid(A);
ListNode* newnode=overtip(mid);
while(A && newnode)
{
if(A->val!=newnode->val)
return false;
A=A->next;
newnode=newnode->next;
}
return true;
}
};