0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Leetcode #328: Odd Even Linked List

0
Posted at
func oddEvenList(_ head: ListNode?) -> ListNode? {
    let dummyNode = ListNode(0)
    dummyNode.next = head
    var odd = head
    var even = head?.next
    var evenHead = even
    while even != nil && even?.next != nil {
        odd?.next = even?.next
        even?.next = even?.next?.next
        odd = odd?.next
        even = even?.next
    }
    odd?.next = evenHead
    return dummyNode.next
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?