6ms C++


  • 0
    W
        ListNode* reverseList(ListNode* head) {
            ListNode *prev{};
            ListNode *mid{head};
            ListNode *next;
            
            while (mid) {
                next = mid->next;
                mid->next = prev;
                prev = mid;
                mid = next;
            }
            
            return prev;
        }
    

Log in to reply
 

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