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
functionListNode(val){this.val=val;this.next=null;}varpartition=function(head,x){vartemp=newListNode();varflag=newListNode();varbig=temp;varsmall=flag;while(head!=null){if(head.val>=x){temp.next=head;temp=temp.next;head=head.next;}else{flag.next=head;flag=flag.next;head=head.next;}}temp.next=null;flag.next=null;varcarry=small;while(carry.next!=null){carry=carry.next;}carry.next=big.next;returnsmall.next;};varhead=newListNode(1);varaaa=head;head.next=newListNode(2);// head = head.next;// head.next = new ListNode(3);// head = head.next;// head.next = new ListNode(2);// head = head.next;// head.next = new ListNode(5);// head = head.next;// head.next = new ListNode(2);console.log(partition(aaa,2))
The text was updated successfully, but these errors were encountered:
习题
思路
创建两个空的链表,遍历原链表,将小于目标的结点放置于其中一个链表,将大于等于的结点放置于另一个链表,再将两个链表拼接在一起
解答
The text was updated successfully, but these errors were encountered: