//递归法
class Solution {
public:
ListNode* reverseList(ListNode* head) {
if(head == NULL || head->next == NULL) return head;
//...
ListNode* p = head->next;
ListNode* n = reverseList(p);
head->next = NULL;
p->next = head;
return n;
}
};
206.[LeetCode]Reverse Linked List
最新推荐文章于 2024-08-25 17:36:33 发布