面试题24. 反转链表
/** * 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) { ListNode *pHead = nullptr; while (head != nullptr) { ListNode *t = new ListNode(head->val); t->next = pHead; pHead = t; head = head->next; } return pHead; } };