该开始以为space O(1)是只能定义一个变量,后来百度才知道是就地逆置;
网上看到这个方法,感觉很巧妙,自己用js写的;
var oddEvenList = function(head) { if(head===null||head.next===null) return head; var odd = head; var even = head.next; var even_head = even; //奇数结尾even==null,偶数结尾even.next==null while(even!==null && even.next!==null){ odd.next = even.next; odd = odd.next; even.next = odd.next; even = even.next; } odd.next = even_head; return head; };