/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head){
if (head == NULL || head->next == NULL) return head;
struct ListNode *tail = head->next;
struct ListNode *new_head = reverseList(tail);
head->next = tail->next;
tail->next = head;
return new_head;
}
leetcode-206:反转链表
最新推荐文章于 2024-05-31 17:17:25 发布