Why my C# solution is exceeding time limit even for 2 node list?


  • 0
    B

    Only copying the first section of my submission below. Why is this exceeding timelimit for [1,2]? Seems it did the minimal. Confused..

                var originalPrevious = head;
                ListNode currentNode, originalNext;
    
                if (head == null)                          
                {
                    return null;
                }
                else
                {
                    currentNode = head.next;
                }
    
                if (currentNode == null)
                {
                    return head;
                }
                else
                {
                    originalNext = currentNode.next;
                }
    
                if (originalNext == null)
                {
                    currentNode.next = head;                 
                    return currentNode;
                }

  • 0

    After that, head points to currentNode, which points back to head. That's a cycle, kind of an infinite list, so likely you're sending the judge into an infinite loop when it checks the result list.


  • 0
    B

    Thank you! Forgot to terminate the list.


Log in to reply
 

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