You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* * @lc app=leetcode id=143 lang=typescript * * [143] Reorder List */// @lc code=start/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } *//** Do not return anything, modify head in-place instead. */functionreorderList(head: ListNode|null): void{// find the middle of this listletslowPointer=head;letfastPointer=head.next;while(fastPointer&&fastPointer.next){slowPointer=slowPointer.next;fastPointer=fastPointer.next.next;}// this is the start of the second listletsecondHead=slowPointer.next;// break down the listslowPointer.next=null;// reverse the second listletprev=null;while(secondHead){consttmp=secondHead.next;secondHead.next=prev;prev=secondHead;secondHead=tmp;}// reorder the listletfirstList=head;letsecondList=prev;while(secondList){consttmp1=firstList.next;consttmp2=secondList.next;firstList.next=secondList;secondList.next=tmp1;firstList=tmp1;secondList=tmp2;}};// @lc code=end
No description provided.
The text was updated successfully, but these errors were encountered: