标签:link 题目 solution init eve lin public tps info
leetcode - 206:https://leetcode-cn.com/problems/reverse-linked-list/
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* ans;
void dfs(ListNode* pre,ListNode* net){
if(net==NULL){
ans = pre;
return;
}
dfs(net,net->next);
net->next=pre;
}
ListNode* reverseList(ListNode* head) {
if(head == NULL) return ans;
dfs(head,head->next);
head->next=NULL;
return ans;
}
};
标签:link 题目 solution init eve lin public tps info
原文地址:https://www.cnblogs.com/baboon/p/13143840.html