func oddEvenList( head *ListNode ) *ListNode { // write code here // 零个或一个节点,直接返回, 最少有两个节点 if head == nil || head.Next == nil { return head } // 奇数链表头 odd := head oddHead := odd // 偶数链表头 even := head.Next evenHead := even // 向后移动的节点 node := head.Next.Next for node != nil { if node != nil { odd.Next = node odd = odd.Next node = node.Next } if node != nil { even.Next = node even = even.Next node = node.Next } } // 这里很重要,偶数链表的最后一个节点的next设置为nil even.Next = node odd.Next = evenHead return oddHead }