206.[LeetCode]Reverse Linked List

//递归法
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;
    }
};

你可能感兴趣的:(LeetCode)