反转链表
注意是借用 假的头节点,这样算法判断开始和结束,就好很多了.
借用头插法.
[]dummy/head
[] [] [] []
head curr
====
class Solution { public: ListNode* reverseList(ListNode* head) { ListNode dummy(-1);//假的头节点 ListNode *curr = head; head = &dummy; while(curr) { ListNode *tmp = curr->next; curr->next = head->next; head->next = curr; curr = tmp; } return dummy.next; } };