/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param head ListNode类 the head * @return bool布尔型 */ #include <stdbool.h> bool isPail(struct ListNode* head ) { if (head == NULL || head->next == NULL) return true; struct ListNode* n1 = head; struct ListNode* head2 = NULL; struct ListNode* pcur = NULL; while (n1) { pcur = (struct ListNode*)malloc(sizeof(struct ListNode)); pcur->val = n1->val; pcur->next = head2; head2 = pcur; n1 = n1->next; } n1 = head; while (n1) { if (n1->val != pcur->val ) return false; n1 = n1->next; pcur = pcur->next; } return true; }