odd_even_linked_list

  • 2022-12-14
  • 浏览 (541)

odd_even_linked_list.go 源码

package main

func oddEvenList(head *ListNode) *ListNode {
	if head == nil {
		return head
	}

	evenHead := head.Next
	odd, even := head, evenHead
	for even != nil && even.Next != nil {
		odd.Next, odd = even.Next, even.Next
		even.Next, even = odd.Next, odd.Next
	}

	odd.Next = evenHead
	return head
}

你可能感兴趣的文章

add_two_numbers

add_two_numbers_ii

intersection_linked_lists

0  赞