题目:Reverse a singly linked list
C代码:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head) {
if(NULL==head||NULL==head->next) return head;
struct ListNode *p=head->next;
head->next=NULL;
struct ListNode *newhead=reverseList(p);
p->next=head;
return newhead;
}