Time limit exceeded problem


  • 0
    P
    struct ListNode* deleteDuplicates(struct ListNode* head) {
        
        struct ListNode* curr = head;
        struct ListNode* next;
        struct ListNode* temp;
        
        if( curr == NULL || curr->next == NULL)
        {
            return head;
        }
        
        next = head->next;
        while(curr != NULL && next != NULL)
        {
            if(curr->val == next->val)
            {
                temp = next;
                curr->next = next->next;
                next = next->next;
                free(temp);
            }
        }
    
        return head;
        
    }
    

    Could someone identify what is wrong with this code? The solution says the time limit has exceeded for certain test cases.


Log in to reply
 

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