/**
* 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==NULL) return true;
ListNode *newHead = NULL;
ListNode *Head=new ListNode(0);
ListNode *tmp;
int count=0;
ListNode *q=Head;
while (head) {
ListNode *t = head->next;
ListNode *tail=new ListNode(0);
tail->val=head->val;
Head->next=tail;
Head=Head->next;
head->next = newHead;
newHead = head;
head = t;
}
head=q->next;
q=q->next;
ListNode *p=newHead;
while(p!=NULL&&q!=NULL)
{
if(p->val!=q->val) return false;
p=p->next;
q=q->next;
}
return true;
}
};
08-04
08-04
08-04