Why I exceed the time limit?


  • 0
    S

    Here's my code

    void reorderList(struct ListNode *head) {
    struct ListNode * h, * tail, * prev;
    for (h = head; h && h->next && h->next->next; h = h->next->next) {
        prev = h;
        tail = prev->next;
        while (tail->next) {
            prev = tail;
            tail = tail->next;
        }
        prev->next = NULL;
        tail->next = h->next;
        h->next = tail;
    }
    

    }


  • 0
    S

    The time complexity of this code is O(N*N), but the solution is O(N).


  • 0
    P

    In leetcode, when you use the complexity O(n^2). It always means you will get a time limit response.


  • 0
    A
    This post is deleted!

Log in to reply
 

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