Reverse a singly linked list.
实现:
class Solution {
public:
ListNode* reverseList(ListNode* head) {
if (head == NULL) return NULL;
ListNode* pfirst = head;
ListNode* pcurr = head;
while (pcurr->next) {
ListNode* tmp = pcurr->next;
pcurr->next = tmp->next;
tmp->next = pfirst;
pfirst = tmp;
}
return pfirst;
}
};