package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
type ListNode = structures.ListNode
func oddEvenList(head *ListNode) *ListNode {
oddHead := &ListNode{Val: 0, Next: nil}
odd := oddHead
evenHead := &ListNode{Val: 0, Next: nil}
even := evenHead
count := 1
for head != nil {
if count%2 == 1 {
odd.Next = head
odd = odd.Next
} else {
even.Next = head
even = even.Next
}
head = head.Next
count++
}
even.Next = nil
odd.Next = evenHead.Next
return oddHead.Next
}