Time Limit Exceeded, unable to figure out why

  • 0
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     struct ListNode *next;
     * };
    struct ListNode* reverseBetween(struct ListNode* head, int m, int n) {
        struct ListNode* current =head;
        struct ListNode* prev = head;
        if(head->next==NULL)return head;
        for(int start=2;start<m;start++){
            prev = prev->next;
            current =current->next;
        current = current->next;
            struct ListNode* temp = current->next;
            printf("Current value : %d", current->val);
            current->next = prev;
            prev =current;
            current = temp;
        return head;

Log in to reply

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