- Reverse Linked List
Reverse a singly linked list.
1、swap in-place
ListNode* reverseList(ListNode* head) {
if(head==NULL || head->next==NULL)
return head;
ListNode *pre = head;
ListNode *p = head->next;
pre->next = NULL;
ListNode *nxt;
while(p!=NULL) {
nxt = p->next;
p->next = pre;
pre = p;
p = nxt;
}
return pre;
}