Reverse a singly linked list.
class Solution { public: ListNode* reverseList(ListNode *head) { if(head == NULL || head->next == NULL) return head; else { ListNode *cur = head, *next_ptr = head->next; head->next = NULL; while(next_ptr) { cur = next_ptr; next_ptr = cur->next; cur->next = head; head = cur; } } return head; } };
[leetcode] Reverse Linked List
原文:http://www.cnblogs.com/lxd2502/p/4478492.html