Skip to content
LC-0328 Medium LeetCode

328. Odd Even Linked List

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 62% Topics: Linked List
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def oddEvenList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if head:
            odd_tail, cur = head, head.next
            while cur and cur.next:
                even_head = odd_tail.next
                odd_tail.next = cur.next
                odd_tail = odd_tail.next
                cur.next = odd_tail.next
                odd_tail.next = even_head
                cur = cur.next
        return head

Solution from kamyu104/LeetCode-Solutions · MIT