题解 | #反转链表#
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
原链表不断取头,新链表头插
class Solution { public: ListNode* ReverseList(ListNode* pHead) { ListNode* newHead = nullptr; while(pHead){ //原链表取头 ListNode* tmp = pHead; pHead = pHead->next; //新链表头插 tmp->next = newHead; newHead = tmp; } return newHead; } };