Why my code is time limit exceed?


  • 0
    C
    class Solution(object):
        def oddEvenList(self, head):
            temp,cur1,cur2=head.next,head,head.next
            count=0
            while temp.next!=None:
                cur1.next=temp.next
                cur1=cur1.next
                temp=temp.next
               
                count = count + 1
            cur1.next=None
            if count%2==0:
                temp.next=cur2
            else:
                cur1.next=cur2
            return head
    
    
    i think my code is O(n)  and space used is O(1) cuz there are numbers of items i use.
    please help me and thanks !

  • 0
    I

    I met the same problem with you. It's very likely that the list you return has a loop. As a result, your program ended normally, however, the OJ didn't end correctly because it was checking a loop list.


Log in to reply
 

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