/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return ListNode类
*/
function oddEvenList( head ) {
// write code here
if(head == null || head.next == null){
return head;
}
// let odd = new ListNode(head.val)
// let even = new ListNode(head.next.val)
let odd = head
let eve = head.next
let even = eve
//奇偶指针改变方向
while(even !== null && even.next !== null){
odd.next = even.next
odd = odd.next
even.next = odd.next
even = even.next
}
odd.next = eve
return head
// let dummy = head
// let odd = dummy
// while(head){
// odd = head
// head = head.next.next
// odd.next = head
// }
// let ev = head.next
// let even = ev
// while(ev){
// even = ev
// ev = ev.next.next
// even.next = ev
// }
// while(odd.next !== null){
// odd = odd.next
// }
// odd.next = ev.next
// return dummy.next
}
module.exports = {
oddEvenList : oddEvenList
};