import { ListNode } from './LinkList' ; param { ListNode } head return { ListNode } function ReorderList ( head ) { if ( head === null || head . next === null ) { return head ; } let slow = head ; let fast = head ; while ( fast . next !== null && fast . next . next !== null ) { slow = slow . next ; fast = fast . next . next ; } let cur = slow . next ; let thePrev = null ; let theNext = null ; while ( cur !== null ) { theNext = cur . next ; cur . next = thePrev ; thePrev = cur ; cur = theNext ; } slow . next = thePrev ; let head1 = head ; let head2 = slow . next ; while ( head1 !== slow ) { slow . next = head2 . next ; head2 . next = head1 . next ; head1 . next = head2 ; head1 = head2 . next ; head2 = slow . next ; } return head ; } export default ReorderList ;