个人感觉不存在 时间复杂度 n 和空间复杂度l 同时存在,以下1.5n也是超出了n
public void reorderList(ListNode head) {
if (head == null){
return;
}
ListNode h = head;
ListNode mid =head;
while (h.next != null && h.next.next != null){
h = h.next.next;
mid = mid.next;
}
ListNode midH = mid;
while (midH.next != null){
ListNode midN = midH.next;
midH.next = midN.next;
midN.next = mid;
mid = midN;
}
h = head;
while (h != null && mid.next != null){
ListNode temp = mid.next;
mid.next = h.next;
h.next = mid;
h = mid.next;
mid = temp;
}
}