0 ms C code.


  • 1
    A
    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     struct ListNode *next;
     * };
     */
    struct ListNode* reverseList(struct ListNode* head) {
    struct ListNode* temp, *prev, *current;
    
    current = head;
    prev = NULL;
        if(head == NULL)
            return head;
        while(current)
            {
                temp = current->next;
                current->next = prev;
                prev = current;
                current = temp;
                
            }
            head = prev;
            return head;
        
    }
    
    

Log in to reply
 

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