题解 | #判断一个链表是否为回文结构#
判断一个链表是否为回文结构
https://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f
将链表转换为数组后判断是否是回文。
_Bool isPail(struct ListNode* head ) { // write code here int* nums = (int*)malloc(sizeof(int)*100001); int cnt = 0; while(head){ nums[cnt++] = head->val; head = head->next; } for(int i = 0; i < cnt/2; i++){ if(nums[i] != nums[cnt-1-i]){ return 0; } } return 1; }