328. Odd Even Linked List
https://leetcode.com/problems/odd-even-linked-list
Python
class Solution:
def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
is_odd = True
odd_head = ListNode(None, None)
odd_node = odd_head
even_head = ListNode(None, None)
even_node = even_head
current = head
while current:
if is_odd:
odd_node.next = current
odd_node = current
else:
even_node.next = current
even_node = current
current = current.next
is_odd = not is_odd
even_node.next = None
odd_node.next = even_head.next
return odd_head.next