Python solution with detailed explanation

  • 0


    Odd Even Linked List

    • Use two sentinel nodes and push odd values on one and even on others.
    class Solution(object):
        def oddEvenList(self, head):
            :type head: ListNode
            :rtype: ListNode
            t_odd = odd = ListNode(-1)
            t_even = even = ListNode(-1)
            odd_ = True
            while head:
                if odd_:
           = head
                    t_odd = head
                    odd_ = False
           = head
                    t_even = head
                    odd_ = True
                head =
   = None

Log in to reply

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