mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 01:49:41 +01:00
17 lines
378 B
Go
17 lines
378 B
Go
package main
|
|
|
|
func oddEvenList(head *ListNode) *ListNode {
|
|
dummies := []ListNode{ListNode{Val: 0, Next: nil}, ListNode{Val: 0, Next: nil}}
|
|
tails := []*ListNode{&dummies[0], &dummies[1]}
|
|
|
|
for idx := 0; head != nil; idx++ {
|
|
tails[idx%2].Next = head
|
|
tails[idx%2] = head
|
|
|
|
head = head.Next
|
|
}
|
|
|
|
tails[0].Next = dummies[1].Next
|
|
tails[1].Next = nil
|
|
return dummies[0].Next
|
|
}
|