Straight forward Python Solution


  • 0
    C
    def oddEvenList(head):
        if not head or not head.next:
            return head
            
        odd = head
        dummy = even = ListNode(-1)
        
        while odd and odd.next and odd.next.next:
            nextEven = odd.next
            odd.next = odd.next.next
            even.next = nextEven
            odd = odd.next
            even = even.next
            
        even.next = odd.next
        odd.next = dummy.next
        return head

Log in to reply
 

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