Simple C++ code


  • 0
    R

    ListNode* reverseList2(ListNode* head) {

        if (!head) return nullptr;
    
        auto tail = head;
    
        while (ListNode *node = tail->next) {
            tail->next = node->next;
            node->next = head;
            head = node;
        }
    
        return head;
    }

Log in to reply
 

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