翻转列表
/**
* 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) {
if(head==NULL|| head->next==NULL)
return head;
ListNode* term = head->next;
head->next=NULL;
return Fun(term,head);
}
ListNode* Fun(ListNode* head,ListNode* pre)
{
ListNode* term = head->next;
head->next = pre;
if(term!=NULL)
return Fun(term,head);
else
return head;
}
};