8ms written in c++


  • 1
    S
    ListNode* reverseList(ListNode* head) {
           if(head == NULL){
               return head;
           }
           
           ListNode* curNode = head;
           ListNode* nextNode = curNode->next;
           curNode->next = NULL;
           while(nextNode != NULL){
              ListNode* tmp = nextNode->next;
              nextNode->next = curNode;
             curNode = nextNode;
             nextNode = tmp;
           }
           return curNode;
        }

Log in to reply
 

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