/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* h;
void DFS(ListNode* head){
if(head==NULL) return ;
if(head->next==NULL){
h=head;
return;
}
DFS(head->next);
head->next->next=head;
head->next=NULL;
}
ListNode* reverseList(ListNode* head) {
DFS(head);
return h;
}
};
原文:https://www.cnblogs.com/cell-coder/p/12394520.html