leetcode 206 反转链表

class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if( head== nullptr )
            return  head;
        if( head->next == nullptr)
            return head
        ListNode* p = reverseList(head->next);
        head->next->next=head;
        head->next = nullptr;
        return  p;
    }
};

 

你可能感兴趣的:(leetcode,算法)