1 ListNode* reverseList(ListNode* head){ 2 if (head==NULL || head->next==NULL) return head; 3 ListNode *pre=head, *cur=pre->next, *post; 4 pre->next = NULL; 5 while (cur!=NULL){ 6 post = cur->next; 7 cur->next = pre; 8 pre = cur; 9 cur = post; 10 } 11 return pre; 12 }
时间: 2024-10-07 05:41:41