206. Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* reverseList(ListNode* head) { if(!head) return head; ListNode * Dummy = new ListNode(-1); ListNode * pCur = head; ListNode * pNext = nullptr; while(pCur){ pNext = pCur->next; pCur->next = Dummy->next; Dummy->next = pCur; pCur = pNext; } return Dummy->next; delete Dummy; } };