leetcode 206. Reverse Linked List
头插法,每次取出后插入新链表的头部。
ListNode* reverseList(ListNode* head) { if (head == NULL) return NULL; ListNode* ret = NULL; while (head) { ListNode* next = head->next; head->next = ret; ret = head; head = next; } return ret; }
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】