bool isPail(struct ListNode* head ) {
// write code here
if(head==NULL || head->next==NULL)
return true;
struct ListNode *p=head,*q,*head2;
head2=(struct ListNode*)malloc(sizeof(struct ListNode));
head2->next=NULL;
while(p!=NULL)
{
q=(struct ListNode*)malloc(sizeof(struct ListNode));
q->val=p->val;
q->next=head2->next;
head2->next=q;
p=p->next;
}
p=head;
while(p!=NULL)
{
if(p->val!=q->val)
return false;
p=p->next;
q=q->next;
}
return true;
}



京公网安备 11010502036488号