My 12 lines code in c, only 0 ms. O(n)


  • 0
    X
    struct ListNode* reverseList(struct ListNode* head) {
    	if (head == NULL) return NULL;
    	ListNode *current = head;
    	ListNode *tail = NULL;
    	while (current) {
    		ListNode *temp = current;
    		current = current->next;
    		temp->next = tail;
    		tail =  temp;
    	}
    	return tail;
    }

Log in to reply
 

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