Could someone tell me why my code timeout for [1,2,3]? For other test cases it seems fine.
if head == None or head.next == None or head.next.next == None: return head ol = head el = head.next eh = el n = el.next count = 3 while n != None and n.next != None: if count % 2 == 1: ol.next = n n = n.next ol = ol.next count += 1 else: el.next = n n = n.next el = el.next count += 1 if count % 2 == 1: ol.next = n n.next = eh else: el.next = n ol.next = eh return head
@AceArthur the next of last evenNode should be null. take care of the next of the last node.