反转链表

ListNode *reverse(ListNode *head){
        if (!head || !head->next) return head;
        auto res = reverse(head->next);
        head->next->next = head;
        head->next = nullptr;
        return res;
    }

 

posted @ 2022-04-19 20:19  Dsad123FFFG6645  阅读(15)  评论(0)    收藏  举报