Simple 5 lines C++ solution


  • 0
    B
    ListNode* reverseList(ListNode* head) {
            
            ListNode* curr = head;
            ListNode* temp;
            ListNode* prev = NULL;
            
           while(curr){
                
                temp = curr;
                curr = curr->next;
                temp->next = prev;
                prev = temp;
                
                
            }
            
            return prev;
        }

Log in to reply
 

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