4ms simple C solution

  • 1

    The idea is simple, just iterate all nodes and process reverse meanwhile.

    struct ListNode* newHead = NULL;
    while (head) {
        struct ListNode* tmpNode = head->next;
        head->next = newHead;
        newHead = head;
        head = tmpNode;
    return newHead;

Log in to reply

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