C++ 6ms 4-line recursive solution --- A simple and fast one


  • 0
    A

    class Solution {
    public:
    ListNode* reverseList(ListNode* head, ListNode* pre = NULL) {
    if (head == NULL) { return pre; }
    ListNode* res = reverseList(head->next, head);
    head->next = pre;
    return res;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.